Skip to content

Commit f7c0566

Browse files
committed
fix(rustc_parse): incorrect span information for macro path expr
Old error output: 3 | let _: usize = $f; | ----- ^ expected `usize`, found struct `Baz` | | | expected due to this New error output: 3 | let _: usize = $f; | ----- ^^ expected `usize`, found struct `Baz` | | | expected due to this
1 parent d562848 commit f7c0566

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ macro_rules! maybe_whole_expr {
4141
let path = path.clone();
4242
$p.bump();
4343
return Ok($p.mk_expr(
44-
$p.token.span,
44+
$p.prev_token.span,
4545
ExprKind::Path(None, path),
4646
AttrVec::new(),
4747
));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
macro_rules! foo {
2+
( $f:path ) => {{
3+
let _: usize = $f; //~ERROR
4+
}};
5+
}
6+
7+
struct Baz;
8+
9+
fn main() {
10+
foo!(Baz);
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-87812-path.rs:3:24
3+
|
4+
LL | let _: usize = $f;
5+
| ----- ^^ expected `usize`, found struct `Baz`
6+
| |
7+
| expected due to this
8+
...
9+
LL | foo!(Baz);
10+
| ---------- in this macro invocation
11+
|
12+
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)