mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
migrate check_for_for_in_in_typo
diagnostic
This commit is contained in:
parent
9ce04e3783
commit
e1d63d1d7c
@ -28,3 +28,7 @@ parser-incorrect-use-of-await =
|
||||
incorrect use of `await`
|
||||
.parentheses-suggestion = `await` is not a method call, remove the parentheses
|
||||
.postfix-suggestion = `await` is a postfix operation
|
||||
|
||||
parser-in-in-typo =
|
||||
expected iterable, found keyword `in`
|
||||
.suggestion = remove the duplicated `in`
|
||||
|
@ -325,6 +325,15 @@ struct IncorrectAwait {
|
||||
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
|
||||
// without causing duplicate errors being emitted when the `Parser`
|
||||
// is dropped.
|
||||
@ -1953,14 +1962,10 @@ impl<'a> Parser<'a> {
|
||||
pub(super) fn check_for_for_in_in_typo(&mut self, in_span: Span) {
|
||||
if self.eat_keyword(kw::In) {
|
||||
// a common typo: `for _ in in bar {}`
|
||||
self.struct_span_err(self.prev_token.span, "expected iterable, found keyword `in`")
|
||||
.span_suggestion_short(
|
||||
in_span.until(self.prev_token.span),
|
||||
"remove the duplicated `in`",
|
||||
String::new(),
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
self.sess.emit_err(InInTypo {
|
||||
span: self.prev_token.span,
|
||||
sugg_span: in_span.until(self.prev_token.span),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user