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
This commit is contained in:
Michael Howell 2021-08-28 17:35:39 -07:00
parent d562848268
commit f7c0566b12
3 changed files with 28 additions and 1 deletions

View file

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

View file

@ -0,0 +1,11 @@
macro_rules! foo {
( $f:path ) => {{
let _: usize = $f; //~ERROR
}};
}
struct Baz;
fn main() {
foo!(Baz);
}

View file

@ -0,0 +1,16 @@
error[E0308]: mismatched types
--> $DIR/issue-87812-path.rs:3:24
|
LL | let _: usize = $f;
| ----- ^^ expected `usize`, found struct `Baz`
| |
| expected due to this
...
LL | foo!(Baz);
| ---------- in this macro invocation
|
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.