Use proper subdiagnostic
This commit is contained in:
parent
8e7783bd13
commit
fe0533638c
1 changed files with 9 additions and 15 deletions
|
@ -1,4 +1,3 @@
|
||||||
use rustc_errors::DecorateLint;
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_macros::{LintDiagnostic, Subdiagnostic};
|
use rustc_macros::{LintDiagnostic, Subdiagnostic};
|
||||||
|
@ -120,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
||||||
)) {
|
)) {
|
||||||
// If it's a trait bound and an opaque that doesn't satisfy it,
|
// If it's a trait bound and an opaque that doesn't satisfy it,
|
||||||
// then we can emit a suggestion to add the bound.
|
// then we can emit a suggestion to add the bound.
|
||||||
let sugg =
|
let add_bound =
|
||||||
match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
|
match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
|
||||||
(ty::Opaque(def_id, _), ty::PredicateKind::Trait(trait_pred)) => Some(AddBound {
|
(ty::Opaque(def_id, _), ty::PredicateKind::Trait(trait_pred)) => Some(AddBound {
|
||||||
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
|
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
|
||||||
|
@ -128,21 +127,14 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
||||||
}),
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let lint = OpaqueHiddenInferredBoundLint {
|
cx.emit_spanned_lint(
|
||||||
|
OPAQUE_HIDDEN_INFERRED_BOUND,
|
||||||
|
pred_span,
|
||||||
|
OpaqueHiddenInferredBoundLint {
|
||||||
ty: cx.tcx.mk_opaque(def_id, ty::InternalSubsts::identity_for_item(cx.tcx, def_id)),
|
ty: cx.tcx.mk_opaque(def_id, ty::InternalSubsts::identity_for_item(cx.tcx, def_id)),
|
||||||
proj_ty: proj_term,
|
proj_ty: proj_term,
|
||||||
assoc_pred_span,
|
assoc_pred_span,
|
||||||
};
|
add_bound,
|
||||||
cx.struct_span_lint(
|
|
||||||
OPAQUE_HIDDEN_INFERRED_BOUND,
|
|
||||||
pred_span,
|
|
||||||
lint.msg(),
|
|
||||||
|diag| {
|
|
||||||
lint.decorate_lint(diag);
|
|
||||||
if let Some(sugg) = sugg {
|
|
||||||
diag.subdiagnostic(sugg);
|
|
||||||
}
|
|
||||||
diag
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -159,6 +151,8 @@ struct OpaqueHiddenInferredBoundLint<'tcx> {
|
||||||
proj_ty: Ty<'tcx>,
|
proj_ty: Ty<'tcx>,
|
||||||
#[label(lint::specifically)]
|
#[label(lint::specifically)]
|
||||||
assoc_pred_span: Span,
|
assoc_pred_span: Span,
|
||||||
|
#[subdiagnostic]
|
||||||
|
add_bound: Option<AddBound<'tcx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue