1
Fork 0

Rollup merge of #101515 - chenyukang:fix-101477, r=fee1-dead

Recover from typo where == is used in place of =

Fixes #101477
This commit is contained in:
Dylan DPC 2022-09-08 20:48:37 +05:30 committed by GitHub
commit 8d2a492d73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 0 deletions

View file

@ -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 {