fix(rustc_parse): incorrect span information for macro block expr

Old error output:

   = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
help: wrap this expression in parentheses
   |
4  |             break '_l $f(;)
   |                         ^ ^

New error output:

   = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
help: wrap this expression in parentheses
   |
4  |             break '_l ($f);
   |                       ^  ^
This commit is contained in:
Michael Howell 2021-08-28 17:28:39 -07:00
parent 926f069950
commit d562848268
3 changed files with 36 additions and 1 deletions

View file

@ -50,7 +50,7 @@ macro_rules! maybe_whole_expr {
let block = block.clone();
$p.bump();
return Ok($p.mk_expr(
$p.token.span,
$p.prev_token.span,
ExprKind::Block(block, None),
AttrVec::new(),
));

View file

@ -0,0 +1,13 @@
#![deny(break_with_label_and_loop)]
macro_rules! foo {
( $f:block ) => {
'_l: loop {
break '_l $f; //~ERROR
}
};
}
fn main() {
let x = foo!({ 3 });
}

View file

@ -0,0 +1,22 @@
error: this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
--> $DIR/issue-87812.rs:6:13
|
LL | break '_l $f;
| ^^^^^^^^^^^^
...
LL | let x = foo!({ 3 });
| ----------- in this macro invocation
|
note: the lint level is defined here
--> $DIR/issue-87812.rs:1:9
|
LL | #![deny(break_with_label_and_loop)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
help: wrap this expression in parentheses
|
LL | break '_l ($f);
| + +
error: aborting due to previous error