Skip to content

Commit e1d63d1

Browse files
committed
migrate check_for_for_in_in_typo diagnostic
1 parent 9ce04e3 commit e1d63d1

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

compiler/rustc_error_messages/locales/en-US/parser.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ parser-incorrect-use-of-await =
2828
incorrect use of `await`
2929
.parentheses-suggestion = `await` is not a method call, remove the parentheses
3030
.postfix-suggestion = `await` is a postfix operation
31+
32+
parser-in-in-typo =
33+
expected iterable, found keyword `in`
34+
.suggestion = remove the duplicated `in`

compiler/rustc_parse/src/parser/diagnostics.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ struct IncorrectAwait {
325325
question_mark: &'static str,
326326
}
327327

328+
#[derive(SessionDiagnostic)]
329+
#[error(slug = "parser-in-in-typo")]
330+
struct InInTypo {
331+
#[primary_span]
332+
span: Span,
333+
#[suggestion(applicability = "machine-applicable")]
334+
sugg_span: Span,
335+
}
336+
328337
// SnapshotParser is used to create a snapshot of the parser
329338
// without causing duplicate errors being emitted when the `Parser`
330339
// is dropped.
@@ -1953,14 +1962,10 @@ impl<'a> Parser<'a> {
19531962
pub(super) fn check_for_for_in_in_typo(&mut self, in_span: Span) {
19541963
if self.eat_keyword(kw::In) {
19551964
// a common typo: `for _ in in bar {}`
1956-
self.struct_span_err(self.prev_token.span, "expected iterable, found keyword `in`")
1957-
.span_suggestion_short(
1958-
in_span.until(self.prev_token.span),
1959-
"remove the duplicated `in`",
1960-
String::new(),
1961-
Applicability::MachineApplicable,
1962-
)
1963-
.emit();
1965+
self.sess.emit_err(InInTypo {
1966+
span: self.prev_token.span,
1967+
sugg_span: in_span.until(self.prev_token.span),
1968+
});
19641969
}
19651970
}
19661971

0 commit comments

Comments
 (0)