diff options
| author | bors <bors@rust-lang.org> | 2019-11-24 14:08:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-24 14:08:08 +0000 |
| commit | 5a1d028d4c8fc15473dc10473c38df162daa7b41 (patch) | |
| tree | 0abaaf8ffc0cc7c811374d3240871c8f15bac545 /src/librustc_parse/parser/diagnostics.rs | |
| parent | b56b23988de532744fd05301f87c329b612700e3 (diff) | |
| parent | 180388670ee38f49578ef2b9eb878c95c4a31e41 (diff) | |
| download | rust-5a1d028d4c8fc15473dc10473c38df162daa7b41.tar.gz rust-5a1d028d4c8fc15473dc10473c38df162daa7b41.zip | |
Auto merge of #66592 - estebank:raw-raw-ah-ah-ah, r=cramertj
Rework raw ident suggestions Use heuristics to determine whethersuggesting raw identifiers is appropriate. Account for raw identifiers when printing a path in a `use` suggestion. Fix #66126.
Diffstat (limited to 'src/librustc_parse/parser/diagnostics.rs')
| -rw-r--r-- | src/librustc_parse/parser/diagnostics.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index eab35a86c69..1b2760cf457 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -225,8 +225,21 @@ impl<'a> Parser<'a> { self.token.span, &format!("expected identifier, found {}", self.this_token_descr()), ); + let valid_follow = &[ + TokenKind::Eq, + TokenKind::Colon, + TokenKind::Comma, + TokenKind::Semi, + TokenKind::ModSep, + TokenKind::OpenDelim(token::DelimToken::Brace), + TokenKind::OpenDelim(token::DelimToken::Paren), + TokenKind::CloseDelim(token::DelimToken::Brace), + TokenKind::CloseDelim(token::DelimToken::Paren), + ]; if let token::Ident(name, false) = self.token.kind { - if Ident::new(name, self.token.span).is_raw_guess() { + if Ident::new(name, self.token.span).is_raw_guess() && + self.look_ahead(1, |t| valid_follow.contains(&t.kind)) + { err.span_suggestion( self.token.span, "you can escape reserved keywords to use them as identifiers", |
