Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect actual span for getting unexpected token from parsing macros #112518

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,9 +1013,15 @@ impl<'a> Parser<'a> {
}

fn error_unexpected_after_dot(&self) {
// FIXME Could factor this out into non_fatal_unexpected or something.
let actual = pprust::token_to_string(&self.token);
self.sess.emit_err(errors::UnexpectedTokenAfterDot { span: self.token.span, actual });
let span = self.token.span;
let sm = self.sess.source_map();
let (span, actual) = match (&self.token.kind, self.subparser_name) {
(token::Eof, Some(_)) if let Ok(actual) = sm.span_to_snippet(sm.next_point(span)) =>
(span.shrink_to_hi(), actual.into()),
_ => (span, actual),
};
self.sess.emit_err(errors::UnexpectedTokenAfterDot { span, actual });
}

// We need an identifier or integer, but the next token is a float.
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/parser/issues/issue-112458.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
println!("{}", x.); //~ ERROR unexpected token: `)`
//~^ ERROR cannot find value `x` in this scope
}
15 changes: 15 additions & 0 deletions tests/ui/parser/issues/issue-112458.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: unexpected token: `)`
--> $DIR/issue-112458.rs:2:22
|
LL | println!("{}", x.);
| ^

error[E0425]: cannot find value `x` in this scope
--> $DIR/issue-112458.rs:2:20
|
LL | println!("{}", x.);
| ^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.