Skip to content

Commit fe05336

Browse files
Use proper subdiagnostic
1 parent 8e7783b commit fe05336

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::DecorateLint;
21
use rustc_hir as hir;
32
use rustc_infer::infer::TyCtxtInferExt;
43
use rustc_macros::{LintDiagnostic, Subdiagnostic};
@@ -120,29 +119,22 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
120119
)) {
121120
// If it's a trait bound and an opaque that doesn't satisfy it,
122121
// then we can emit a suggestion to add the bound.
123-
let sugg =
122+
let add_bound =
124123
match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
125124
(ty::Opaque(def_id, _), ty::PredicateKind::Trait(trait_pred)) => Some(AddBound {
126125
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
127126
trait_ref: trait_pred.print_modifiers_and_trait_path(),
128127
}),
129128
_ => None,
130129
};
131-
let lint = OpaqueHiddenInferredBoundLint {
132-
ty: cx.tcx.mk_opaque(def_id, ty::InternalSubsts::identity_for_item(cx.tcx, def_id)),
133-
proj_ty: proj_term,
134-
assoc_pred_span,
135-
};
136-
cx.struct_span_lint(
130+
cx.emit_spanned_lint(
137131
OPAQUE_HIDDEN_INFERRED_BOUND,
138132
pred_span,
139-
lint.msg(),
140-
|diag| {
141-
lint.decorate_lint(diag);
142-
if let Some(sugg) = sugg {
143-
diag.subdiagnostic(sugg);
144-
}
145-
diag
133+
OpaqueHiddenInferredBoundLint {
134+
ty: cx.tcx.mk_opaque(def_id, ty::InternalSubsts::identity_for_item(cx.tcx, def_id)),
135+
proj_ty: proj_term,
136+
assoc_pred_span,
137+
add_bound,
146138
},
147139
);
148140
}
@@ -159,6 +151,8 @@ struct OpaqueHiddenInferredBoundLint<'tcx> {
159151
proj_ty: Ty<'tcx>,
160152
#[label(lint::specifically)]
161153
assoc_pred_span: Span,
154+
#[subdiagnostic]
155+
add_bound: Option<AddBound<'tcx>>,
162156
}
163157

164158
#[derive(Subdiagnostic)]

0 commit comments

Comments
 (0)