diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-09-08 20:48:37 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-08 20:48:37 +0530 |
| commit | 8d2a492d73761d78cc8a95640428dc0b05e74060 (patch) | |
| tree | 3d8b12e197aa062012993a004f3eee1e31b0f644 /compiler/rustc_parse/src/parser/diagnostics.rs | |
| parent | 2904060314e857c3b973f6ac17823fd483d8a01f (diff) | |
| parent | ddb225f1f57882c4f87d99d585fab982461d1fd9 (diff) | |
| download | rust-8d2a492d73761d78cc8a95640428dc0b05e74060.tar.gz rust-8d2a492d73761d78cc8a95640428dc0b05e74060.zip | |
Rollup merge of #101515 - chenyukang:fix-101477, r=fee1-dead
Recover from typo where == is used in place of = Fixes #101477
Diffstat (limited to 'compiler/rustc_parse/src/parser/diagnostics.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index ad49227222b..be524db785b 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -713,6 +713,14 @@ pub(crate) struct RemoveLet { pub span: Span, } +#[derive(SessionDiagnostic)] +#[diag(parser::use_eq_instead)] +pub(crate) struct UseEqInstead { + #[primary_span] + #[suggestion_short(applicability = "machine-applicable", code = "=")] + pub span: Span, +} + // SnapshotParser is used to create a snapshot of the parser // without causing duplicate errors being emitted when the `Parser` // is dropped. @@ -957,6 +965,14 @@ impl<'a> Parser<'a> { } } + if self.token.kind == TokenKind::EqEq + && self.prev_token.is_ident() + && expected.iter().any(|tok| matches!(tok, TokenType::Token(TokenKind::Eq))) + { + // Likely typo: `=` → `==` in let expr or enum item + return Err(self.sess.create_err(UseEqInstead { span: self.token.span })); + } + let expect = tokens_to_string(&expected); let actual = super::token_descr(&self.token); let (msg_exp, (label_sp, label_exp)) = if expected.len() > 1 { |
