@@ -245,8 +245,8 @@ fn type_param_predicates<'a, 'tcx>(
245245 use rustc:: hir:: * ;
246246
247247 // In the AST, bounds can derive from two places. Either
248- // written inline like `<T: Foo>` or in a where clause like
249- // `where T: Foo`.
248+ // written inline like `<T : Foo>` or in a where clause like
249+ // `where T : Foo`.
250250
251251 let param_id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
252252 let param_owner = tcx. hir . ty_param_owner ( param_id) ;
@@ -317,12 +317,12 @@ fn type_param_predicates<'a, 'tcx>(
317317 let icx = ItemCtxt :: new ( tcx, item_def_id) ;
318318 result
319319 . predicates
320- . extend ( icx. type_parameter_bounds_in_generics ( ast_generics, param_id, ty) ) ;
320+ . extend ( icx. type_parameter_bounds_in_generics ( ast_generics, param_id, ty, true ) ) ;
321321 result
322322}
323323
324324impl < ' a , ' tcx > ItemCtxt < ' a , ' tcx > {
325- /// Find bounds from hir::Generics. This requires scanning through the
325+ /// Find bounds from ` hir::Generics` . This requires scanning through the
326326 /// AST. We do this to avoid having to convert *all* the bounds, which
327327 /// would create artificial cycles. Instead we can only convert the
328328 /// bounds for a type parameter `X` if `X::Foo` is used.
@@ -331,6 +331,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
331331 ast_generics : & hir:: Generics ,
332332 param_id : ast:: NodeId ,
333333 ty : Ty < ' tcx > ,
334+ only_self_bounds : bool ,
334335 ) -> Vec < ( ty:: Predicate < ' tcx > , Span ) > {
335336 let from_ty_params = ast_generics
336337 . params
@@ -350,9 +351,21 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
350351 hir:: WherePredicate :: BoundPredicate ( ref bp) => Some ( bp) ,
351352 _ => None ,
352353 } )
353- . filter ( |bp| is_param ( self . tcx , & bp. bounded_ty , param_id) )
354- . flat_map ( |bp| bp. bounds . iter ( ) )
355- . flat_map ( |b| predicates_from_bound ( self , ty, b) ) ;
354+ . flat_map ( |bp| {
355+ let bt = if is_param ( self . tcx , & bp. bounded_ty , param_id) {
356+ Some ( ty)
357+ } else {
358+ if only_self_bounds {
359+ None
360+ } else {
361+ Some ( self . to_ty ( & bp. bounded_ty ) )
362+ }
363+ } ;
364+ bp. bounds . iter ( ) . filter_map ( move |b| {
365+ if let Some ( bt) = bt { Some ( ( bt, b) ) } else { None }
366+ } )
367+ } )
368+ . flat_map ( |( bt, b) | predicates_from_bound ( self , bt, b) ) ;
356369
357370 from_ty_params. chain ( from_where_clauses) . collect ( )
358371 }
@@ -690,22 +703,25 @@ fn super_predicates_of<'a, 'tcx>(
690703
691704 let icx = ItemCtxt :: new ( tcx, trait_def_id) ;
692705
693- // Convert the bounds that follow the colon, e.g. `Bar+ Zed` in `trait Foo : Bar+ Zed`.
706+ // Convert the bounds that follow the colon, e.g. `Bar + Zed` in `trait Foo : Bar + Zed`.
694707 let self_param_ty = tcx. mk_self_type ( ) ;
695708 let superbounds1 = compute_bounds ( & icx, self_param_ty, bounds, SizedByDefault :: No , item. span ) ;
696709
697710 let superbounds1 = superbounds1. predicates ( tcx, self_param_ty) ;
698711
699712 // Convert any explicit superbounds in the where clause,
700713 // e.g. `trait Foo where Self : Bar`:
701- let superbounds2 = icx. type_parameter_bounds_in_generics ( generics, item. id , self_param_ty) ;
714+ let is_trait_alias = ty:: is_trait_alias ( tcx, trait_def_id) ;
715+ let superbounds2 = icx. type_parameter_bounds_in_generics (
716+ generics, item. id , self_param_ty, !is_trait_alias) ;
702717
703718 // Combine the two lists to form the complete set of superbounds:
704719 let superbounds: Vec < _ > = superbounds1. into_iter ( ) . chain ( superbounds2) . collect ( ) ;
705720
706721 // Now require that immediate supertraits are converted,
707722 // which will, in turn, reach indirect supertraits.
708723 for & ( pred, span) in & superbounds {
724+ debug ! ( "superbound: {:?}" , pred) ;
709725 if let ty:: Predicate :: Trait ( bound) = pred {
710726 tcx. at ( span) . super_predicates_of ( bound. def_id ( ) ) ;
711727 }
@@ -2007,10 +2023,10 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(
20072023 }
20082024}
20092025
2010- /// Converts a specific GenericBound from the AST into a set of
2026+ /// Converts a specific ` GenericBound` from the AST into a set of
20112027/// predicates that apply to the self-type. A vector is returned
2012- /// because this can be anywhere from 0 predicates (`T: ?Sized` adds no
2013- /// predicates) to 1 (`T: Foo`) to many (`T: Bar<X=i32>` adds `T: Bar`
2028+ /// because this can be anywhere from zero predicates (`T : ?Sized` adds no
2029+ /// predicates) to one (`T : Foo`) to many (`T : Bar<X=i32>` adds `T : Bar`
20142030/// and `<T as Bar>::X == i32`).
20152031fn predicates_from_bound < ' tcx > (
20162032 astconv : & dyn AstConv < ' tcx , ' tcx > ,
0 commit comments