-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
emit error with span for empty asserts #56491
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
r? @estebank |
src/libsyntax_ext/assert.rs
Outdated
@@ -24,6 +24,12 @@ pub fn expand_assert<'cx>( | |||
tts: &[TokenTree], | |||
) -> Box<dyn MacResult + 'cx> { | |||
let mut parser = cx.new_parser_from_tts(tts); | |||
|
|||
if parser.token == token::Eof { | |||
cx.span_err(sp, "requires a boolean expression"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change!
Could you change this to something closer to
cx.struct_span_err(sp, "macro call requires boolean expression as argument")
.span_label(sp, "boolean expression required")
.emit();
Ideally you'd add a Applicability::MaybeIncorrect
suggestion as well showing what the correct code would be, but that'd be overkill for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
--> $DIR/assert.rs:2:5 | ||
| | ||
LL | assert!(); //~ ERROR requires a boolean expression | ||
| ^^^^^^^^^^ boolean expression required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to point at the (empty) argument list, but this is already quite an improvement.
@bors r+ rollup |
📌 Commit a367cec has been approved by |
emit error with span for empty asserts Fixes rust-lang#55547.
This commit completely removes usage of the `panictry!` macro from outside libsyntax. The macro causes parse errors to be fatal, so using it in libsyntax_ext caused parse failures *within* a syntax extension to be fatal, which is probably not intended. Furthermore, this commit adds spans to diagnostics emitted by empty extensions if they were missing, à la rust-lang#56491.
make `panictry!` private to libsyntax This commit completely removes usage of the `panictry!` macro from outside libsyntax. The macro causes parse errors to be fatal, so using it in libsyntax_ext caused parse failures *within* a syntax extension to be fatal, which is probably not intended. Furthermore, this commit adds spans to diagnostics emitted by empty extensions if they were missing, à la rust-lang#56491.
make `panictry!` private to libsyntax This commit completely removes usage of the `panictry!` macro from outside libsyntax. The macro causes parse errors to be fatal, so using it in libsyntax_ext caused parse failures *within* a syntax extension to be fatal, which is probably not intended. Furthermore, this commit adds spans to diagnostics emitted by empty extensions if they were missing, à la #56491.
Fixes #55547.