mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 14:31:55 +00:00
Rollup merge of #109251 - MU001999:master, r=Nilstrieb
Suggest surrounding the macro with `{}` to interpret as a statement Fixes #109237
This commit is contained in:
commit
7e5705e5c6
@ -245,12 +245,24 @@ pub(super) fn emit_frag_parse_err(
|
||||
e.note(
|
||||
"the macro call doesn't expand to an expression, but it can expand to a statement",
|
||||
);
|
||||
e.span_suggestion_verbose(
|
||||
site_span.shrink_to_hi(),
|
||||
"add `;` to interpret the expansion as a statement",
|
||||
";",
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
||||
if parser.token == token::Semi {
|
||||
if let Ok(snippet) = parser.sess.source_map().span_to_snippet(site_span) {
|
||||
e.span_suggestion_verbose(
|
||||
site_span,
|
||||
"surround the macro invocation with `{}` to interpret the expansion as a statement",
|
||||
format!("{{ {}; }}", snippet),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
e.span_suggestion_verbose(
|
||||
site_span.shrink_to_hi(),
|
||||
"add `;` to interpret the expansion as a statement",
|
||||
";",
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => annotate_err_with_kind(&mut e, kind, site_span),
|
||||
|
7
tests/ui/macros/issue-109237.rs
Normal file
7
tests/ui/macros/issue-109237.rs
Normal file
@ -0,0 +1,7 @@
|
||||
macro_rules! statement {
|
||||
() => {;}; //~ ERROR expected expression
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = statement!();
|
||||
}
|
18
tests/ui/macros/issue-109237.stderr
Normal file
18
tests/ui/macros/issue-109237.stderr
Normal file
@ -0,0 +1,18 @@
|
||||
error: expected expression, found `;`
|
||||
--> $DIR/issue-109237.rs:2:12
|
||||
|
|
||||
LL | () => {;};
|
||||
| ^ expected expression
|
||||
...
|
||||
LL | let _ = statement!();
|
||||
| ------------ in this macro invocation
|
||||
|
|
||||
= note: the macro call doesn't expand to an expression, but it can expand to a statement
|
||||
= note: this error originates in the macro `statement` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: surround the macro invocation with `{}` to interpret the expansion as a statement
|
||||
|
|
||||
LL | let _ = { statement!(); };
|
||||
| ~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user