@@ -15,7 +15,7 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt;
15
15
use crate :: traits:: { self , Obligation , ObligationCause } ;
16
16
use rustc:: ty:: subst:: { InternalSubsts , Subst } ;
17
17
use rustc:: ty:: { self , Predicate , ToPredicate , Ty , TyCtxt , TypeFoldable , WithConstness } ;
18
- use rustc_errors:: Applicability ;
18
+ use rustc_errors:: { Applicability , FatalError } ;
19
19
use rustc_hir as hir;
20
20
use rustc_hir:: def_id:: DefId ;
21
21
use rustc_session:: lint:: builtin:: WHERE_CLAUSES_OBJECT_SAFETY ;
@@ -170,6 +170,24 @@ fn object_safety_violations_for_trait(
170
170
violations
171
171
}
172
172
173
+ fn trait_bound_spans < ' tcx > (
174
+ tcx : TyCtxt < ' tcx > ,
175
+ bounds : hir:: GenericBounds < ' tcx > ,
176
+ ) -> impl ' tcx + Iterator < Item = Span > {
177
+ bounds. iter ( ) . filter_map ( move |b| match b {
178
+ hir:: GenericBound :: Trait ( trait_ref, hir:: TraitBoundModifier :: None )
179
+ if trait_has_sized_self (
180
+ tcx,
181
+ trait_ref. trait_ref . trait_def_id ( ) . unwrap_or_else ( || FatalError . raise ( ) ) ,
182
+ ) =>
183
+ {
184
+ // Fetch spans for supertraits that are `Sized`: `trait T: Super`
185
+ Some ( trait_ref. span )
186
+ }
187
+ _ => None ,
188
+ } )
189
+ }
190
+
173
191
fn get_sized_bounds ( tcx : TyCtxt < ' _ > , trait_def_id : DefId ) -> SmallVec < [ Span ; 1 ] > {
174
192
tcx. hir ( )
175
193
. get_if_local ( trait_def_id)
@@ -189,33 +207,14 @@ fn get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]>
189
207
{
190
208
// Fetch spans for trait bounds that are Sized:
191
209
// `trait T where Self: Pred`
192
- Some ( pred. bounds . iter ( ) . filter_map ( |b| match b {
193
- hir:: GenericBound :: Trait (
194
- trait_ref,
195
- hir:: TraitBoundModifier :: None ,
196
- ) if trait_has_sized_self (
197
- tcx,
198
- trait_ref. trait_ref . trait_def_id ( ) ,
199
- ) =>
200
- {
201
- Some ( trait_ref. span )
202
- }
203
- _ => None ,
204
- } ) )
210
+ Some ( trait_bound_spans ( tcx, pred. bounds ) )
205
211
}
206
212
_ => None ,
207
213
}
208
214
} )
209
215
. flatten ( )
210
- . chain ( bounds. iter ( ) . filter_map ( |b| match b {
211
- hir:: GenericBound :: Trait ( trait_ref, hir:: TraitBoundModifier :: None )
212
- if trait_has_sized_self ( tcx, trait_ref. trait_ref . trait_def_id ( ) ) =>
213
- {
214
- // Fetch spans for supertraits that are `Sized`: `trait T: Super`
215
- Some ( trait_ref. span )
216
- }
217
- _ => None ,
218
- } ) )
216
+ // Fetch spans for supertraits that are `Sized`: `trait T: Super`.
217
+ . chain ( trait_bound_spans ( tcx, bounds) )
219
218
. collect :: < SmallVec < [ Span ; 1 ] > > ( ) ,
220
219
) ,
221
220
_ => None ,
0 commit comments