1
- use rustc_errors:: DecorateLint ;
2
1
use rustc_hir as hir;
3
2
use rustc_infer:: infer:: TyCtxtInferExt ;
4
3
use rustc_macros:: { LintDiagnostic , Subdiagnostic } ;
@@ -120,29 +119,22 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
120
119
) ) {
121
120
// If it's a trait bound and an opaque that doesn't satisfy it,
122
121
// then we can emit a suggestion to add the bound.
123
- let sugg =
122
+ let add_bound =
124
123
match ( proj_term. kind ( ) , assoc_pred. kind ( ) . skip_binder ( ) ) {
125
124
( ty:: Opaque ( def_id, _) , ty:: PredicateKind :: Trait ( trait_pred) ) => Some ( AddBound {
126
125
suggest_span : cx. tcx . def_span ( * def_id) . shrink_to_hi ( ) ,
127
126
trait_ref : trait_pred. print_modifiers_and_trait_path ( ) ,
128
127
} ) ,
129
128
_ => None ,
130
129
} ;
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 (
137
131
OPAQUE_HIDDEN_INFERRED_BOUND ,
138
132
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,
146
138
} ,
147
139
) ;
148
140
}
@@ -159,6 +151,8 @@ struct OpaqueHiddenInferredBoundLint<'tcx> {
159
151
proj_ty : Ty < ' tcx > ,
160
152
#[ label( lint:: specifically) ]
161
153
assoc_pred_span : Span ,
154
+ #[ subdiagnostic]
155
+ add_bound : Option < AddBound < ' tcx > > ,
162
156
}
163
157
164
158
#[ derive( Subdiagnostic ) ]
0 commit comments