Skip to content

Commit bd4d1cd

Browse files
committed
migrate maybe_recover_from_bad_qpath_stage_2 diagnostic
1 parent 16a0d03 commit bd4d1cd

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ parser-add-paren = try adding parentheses
1414
parser-forgot-paren = perhaps you forgot parentheses?
1515
1616
parser-expect-path = expected a path
17+
18+
parser-maybe-recover-from-bad-qpath-stage-2 =
19+
missing angle brackets in associated item path
20+
.suggestion = try: `{$ty}`

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ pub enum BadTypePlusSub {
286286
},
287287
}
288288

289+
#[derive(SessionDiagnostic)]
290+
#[error(slug = "parser-maybe-recover-from-bad-qpath-stage-2")]
291+
struct BadQPathStage2 {
292+
#[primary_span]
293+
#[suggestion(applicability = "maybe-incorrect")]
294+
span: Span,
295+
ty: String,
296+
}
297+
289298
// SnapshotParser is used to create a snapshot of the parser
290299
// without causing duplicate errors being emitted when the `Parser`
291300
// is dropped.
@@ -1469,15 +1478,10 @@ impl<'a> Parser<'a> {
14691478
path.span = ty_span.to(self.prev_token.span);
14701479

14711480
let ty_str = self.span_to_snippet(ty_span).unwrap_or_else(|_| pprust::ty_to_string(&ty));
1472-
self.struct_span_err(path.span, "missing angle brackets in associated item path")
1473-
.span_suggestion(
1474-
// This is a best-effort recovery.
1475-
path.span,
1476-
"try",
1477-
format!("<{}>::{}", ty_str, pprust::path_to_string(&path)),
1478-
Applicability::MaybeIncorrect,
1479-
)
1480-
.emit();
1481+
self.sess.emit_err(BadQPathStage2 {
1482+
span: path.span,
1483+
ty: format!("<{}>::{}", ty_str, pprust::path_to_string(&path)),
1484+
});
14811485

14821486
let path_span = ty_span.shrink_to_hi(); // Use an empty path since `position == 0`.
14831487
Ok(P(T::recovered(Some(QSelf { ty, path_span, position: 0 }), path)))

0 commit comments

Comments
 (0)