migrate check_for_for_in_in_typo diagnostic

This commit is contained in:
Christian Poveda 2022-05-31 16:28:05 -05:00
parent 9ce04e3783
commit e1d63d1d7c
No known key found for this signature in database
GPG Key ID: 27525EF5E7420A50
2 changed files with 17 additions and 8 deletions

View File

@ -28,3 +28,7 @@ parser-incorrect-use-of-await =
incorrect use of `await` incorrect use of `await`
.parentheses-suggestion = `await` is not a method call, remove the parentheses .parentheses-suggestion = `await` is not a method call, remove the parentheses
.postfix-suggestion = `await` is a postfix operation .postfix-suggestion = `await` is a postfix operation
parser-in-in-typo =
expected iterable, found keyword `in`
.suggestion = remove the duplicated `in`

View File

@ -325,6 +325,15 @@ struct IncorrectAwait {
question_mark: &'static str, question_mark: &'static str,
} }
#[derive(SessionDiagnostic)]
#[error(slug = "parser-in-in-typo")]
struct InInTypo {
#[primary_span]
span: Span,
#[suggestion(applicability = "machine-applicable")]
sugg_span: Span,
}
// SnapshotParser is used to create a snapshot of the parser // SnapshotParser is used to create a snapshot of the parser
// without causing duplicate errors being emitted when the `Parser` // without causing duplicate errors being emitted when the `Parser`
// is dropped. // is dropped.
@ -1953,14 +1962,10 @@ impl<'a> Parser<'a> {
pub(super) fn check_for_for_in_in_typo(&mut self, in_span: Span) { pub(super) fn check_for_for_in_in_typo(&mut self, in_span: Span) {
if self.eat_keyword(kw::In) { if self.eat_keyword(kw::In) {
// a common typo: `for _ in in bar {}` // a common typo: `for _ in in bar {}`
self.struct_span_err(self.prev_token.span, "expected iterable, found keyword `in`") self.sess.emit_err(InInTypo {
.span_suggestion_short( span: self.prev_token.span,
in_span.until(self.prev_token.span), sugg_span: in_span.until(self.prev_token.span),
"remove the duplicated `in`", });
String::new(),
Applicability::MachineApplicable,
)
.emit();
} }
} }