migrate maybe_recover_from_bad_qpath_stage_2
diagnostic
This commit is contained in:
parent
16a0d03698
commit
bd4d1cd7a2
2 changed files with 17 additions and 9 deletions
|
@ -14,3 +14,7 @@ parser-add-paren = try adding parentheses
|
||||||
parser-forgot-paren = perhaps you forgot parentheses?
|
parser-forgot-paren = perhaps you forgot parentheses?
|
||||||
|
|
||||||
parser-expect-path = expected a path
|
parser-expect-path = expected a path
|
||||||
|
|
||||||
|
parser-maybe-recover-from-bad-qpath-stage-2 =
|
||||||
|
missing angle brackets in associated item path
|
||||||
|
.suggestion = try: `{$ty}`
|
||||||
|
|
|
@ -286,6 +286,15 @@ pub enum BadTypePlusSub {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(slug = "parser-maybe-recover-from-bad-qpath-stage-2")]
|
||||||
|
struct BadQPathStage2 {
|
||||||
|
#[primary_span]
|
||||||
|
#[suggestion(applicability = "maybe-incorrect")]
|
||||||
|
span: Span,
|
||||||
|
ty: String,
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -1469,15 +1478,10 @@ impl<'a> Parser<'a> {
|
||||||
path.span = ty_span.to(self.prev_token.span);
|
path.span = ty_span.to(self.prev_token.span);
|
||||||
|
|
||||||
let ty_str = self.span_to_snippet(ty_span).unwrap_or_else(|_| pprust::ty_to_string(&ty));
|
let ty_str = self.span_to_snippet(ty_span).unwrap_or_else(|_| pprust::ty_to_string(&ty));
|
||||||
self.struct_span_err(path.span, "missing angle brackets in associated item path")
|
self.sess.emit_err(BadQPathStage2 {
|
||||||
.span_suggestion(
|
span: path.span,
|
||||||
// This is a best-effort recovery.
|
ty: format!("<{}>::{}", ty_str, pprust::path_to_string(&path)),
|
||||||
path.span,
|
});
|
||||||
"try",
|
|
||||||
format!("<{}>::{}", ty_str, pprust::path_to_string(&path)),
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
|
|
||||||
let path_span = ty_span.shrink_to_hi(); // Use an empty path since `position == 0`.
|
let path_span = ty_span.shrink_to_hi(); // Use an empty path since `position == 0`.
|
||||||
Ok(P(T::recovered(Some(QSelf { ty, path_span, position: 0 }), path)))
|
Ok(P(T::recovered(Some(QSelf { ty, path_span, position: 0 }), path)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue