Suggest surrounding the macro with {}
to interpret as a statement
This commit is contained in:
parent
511364e787
commit
550e3087d1
3 changed files with 43 additions and 6 deletions
|
@ -245,6 +245,17 @@ pub(super) fn emit_frag_parse_err(
|
||||||
e.note(
|
e.note(
|
||||||
"the macro call doesn't expand to an expression, but it can expand to a statement",
|
"the macro call doesn't expand to an expression, but it can expand to a statement",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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(
|
e.span_suggestion_verbose(
|
||||||
site_span.shrink_to_hi(),
|
site_span.shrink_to_hi(),
|
||||||
"add `;` to interpret the expansion as a statement",
|
"add `;` to interpret the expansion as a statement",
|
||||||
|
@ -252,6 +263,7 @@ pub(super) fn emit_frag_parse_err(
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => annotate_err_with_kind(&mut e, kind, site_span),
|
_ => 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…
Add table
Add a link
Reference in a new issue