@@ -15,7 +15,7 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt;
1515use crate :: traits:: { self , Obligation , ObligationCause } ;
1616use rustc:: ty:: subst:: { InternalSubsts , Subst } ;
1717use rustc:: ty:: { self , Predicate , ToPredicate , Ty , TyCtxt , TypeFoldable , WithConstness } ;
18- use rustc_errors:: Applicability ;
18+ use rustc_errors:: { Applicability , FatalError } ;
1919use rustc_hir as hir;
2020use rustc_hir:: def_id:: DefId ;
2121use rustc_session:: lint:: builtin:: WHERE_CLAUSES_OBJECT_SAFETY ;
@@ -170,6 +170,24 @@ fn object_safety_violations_for_trait(
170170 violations
171171}
172172
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+
173191fn get_sized_bounds ( tcx : TyCtxt < ' _ > , trait_def_id : DefId ) -> SmallVec < [ Span ; 1 ] > {
174192 tcx. hir ( )
175193 . get_if_local ( trait_def_id)
@@ -189,33 +207,14 @@ fn get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]>
189207 {
190208 // Fetch spans for trait bounds that are Sized:
191209 // `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 ) )
205211 }
206212 _ => None ,
207213 }
208214 } )
209215 . 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) )
219218 . collect :: < SmallVec < [ Span ; 1 ] > > ( ) ,
220219 ) ,
221220 _ => None ,
0 commit comments