Skip to content

Commit d562848

Browse files
committed
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); | ^ ^
1 parent 926f069 commit d562848

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ macro_rules! maybe_whole_expr {
5050
let block = block.clone();
5151
$p.bump();
5252
return Ok($p.mk_expr(
53-
$p.token.span,
53+
$p.prev_token.span,
5454
ExprKind::Block(block, None),
5555
AttrVec::new(),
5656
));

src/test/ui/parser/issue-87812.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![deny(break_with_label_and_loop)]
2+
3+
macro_rules! foo {
4+
( $f:block ) => {
5+
'_l: loop {
6+
break '_l $f; //~ERROR
7+
}
8+
};
9+
}
10+
11+
fn main() {
12+
let x = foo!({ 3 });
13+
}

src/test/ui/parser/issue-87812.stderr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
2+
--> $DIR/issue-87812.rs:6:13
3+
|
4+
LL | break '_l $f;
5+
| ^^^^^^^^^^^^
6+
...
7+
LL | let x = foo!({ 3 });
8+
| ----------- in this macro invocation
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/issue-87812.rs:1:9
12+
|
13+
LL | #![deny(break_with_label_and_loop)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15+
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
16+
help: wrap this expression in parentheses
17+
|
18+
LL | break '_l ($f);
19+
| + +
20+
21+
error: aborting due to previous error
22+

0 commit comments

Comments
 (0)