Skip to content

Commit 9f2c21c

Browse files
authored
Rollup merge of #112518 - chenyukang:yukang-fix-112458, r=davidtwco
Detect actual span for getting unexpected token from parsing macros Fixes #112458
2 parents f42f19b + 0220c0b commit 9f2c21c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

compiler/rustc_parse/src/parser/expr.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,15 @@ impl<'a> Parser<'a> {
10131013
}
10141014

10151015
fn error_unexpected_after_dot(&self) {
1016-
// FIXME Could factor this out into non_fatal_unexpected or something.
10171016
let actual = pprust::token_to_string(&self.token);
1018-
self.sess.emit_err(errors::UnexpectedTokenAfterDot { span: self.token.span, actual });
1017+
let span = self.token.span;
1018+
let sm = self.sess.source_map();
1019+
let (span, actual) = match (&self.token.kind, self.subparser_name) {
1020+
(token::Eof, Some(_)) if let Ok(actual) = sm.span_to_snippet(sm.next_point(span)) =>
1021+
(span.shrink_to_hi(), actual.into()),
1022+
_ => (span, actual),
1023+
};
1024+
self.sess.emit_err(errors::UnexpectedTokenAfterDot { span, actual });
10191025
}
10201026

10211027
// We need an identifier or integer, but the next token is a float.
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
println!("{}", x.); //~ ERROR unexpected token: `)`
3+
//~^ ERROR cannot find value `x` in this scope
4+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: unexpected token: `)`
2+
--> $DIR/issue-112458.rs:2:22
3+
|
4+
LL | println!("{}", x.);
5+
| ^
6+
7+
error[E0425]: cannot find value `x` in this scope
8+
--> $DIR/issue-112458.rs:2:20
9+
|
10+
LL | println!("{}", x.);
11+
| ^ not found in this scope
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)