@@ -245,8 +245,8 @@ fn type_param_predicates<'a, 'tcx>(
245
245
use rustc:: hir:: * ;
246
246
247
247
// 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`.
250
250
251
251
let param_id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
252
252
let param_owner = tcx. hir . ty_param_owner ( param_id) ;
@@ -317,12 +317,12 @@ fn type_param_predicates<'a, 'tcx>(
317
317
let icx = ItemCtxt :: new ( tcx, item_def_id) ;
318
318
result
319
319
. 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 ) ) ;
321
321
result
322
322
}
323
323
324
324
impl < ' 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
326
326
/// AST. We do this to avoid having to convert *all* the bounds, which
327
327
/// would create artificial cycles. Instead we can only convert the
328
328
/// bounds for a type parameter `X` if `X::Foo` is used.
@@ -331,6 +331,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
331
331
ast_generics : & hir:: Generics ,
332
332
param_id : ast:: NodeId ,
333
333
ty : Ty < ' tcx > ,
334
+ only_self_bounds : bool ,
334
335
) -> Vec < ( ty:: Predicate < ' tcx > , Span ) > {
335
336
let from_ty_params = ast_generics
336
337
. params
@@ -350,9 +351,21 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
350
351
hir:: WherePredicate :: BoundPredicate ( ref bp) => Some ( bp) ,
351
352
_ => None ,
352
353
} )
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) ) ;
356
369
357
370
from_ty_params. chain ( from_where_clauses) . collect ( )
358
371
}
@@ -690,22 +703,25 @@ fn super_predicates_of<'a, 'tcx>(
690
703
691
704
let icx = ItemCtxt :: new ( tcx, trait_def_id) ;
692
705
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`.
694
707
let self_param_ty = tcx. mk_self_type ( ) ;
695
708
let superbounds1 = compute_bounds ( & icx, self_param_ty, bounds, SizedByDefault :: No , item. span ) ;
696
709
697
710
let superbounds1 = superbounds1. predicates ( tcx, self_param_ty) ;
698
711
699
712
// Convert any explicit superbounds in the where clause,
700
713
// 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) ;
702
717
703
718
// Combine the two lists to form the complete set of superbounds:
704
719
let superbounds: Vec < _ > = superbounds1. into_iter ( ) . chain ( superbounds2) . collect ( ) ;
705
720
706
721
// Now require that immediate supertraits are converted,
707
722
// which will, in turn, reach indirect supertraits.
708
723
for & ( pred, span) in & superbounds {
724
+ debug ! ( "superbound: {:?}" , pred) ;
709
725
if let ty:: Predicate :: Trait ( bound) = pred {
710
726
tcx. at ( span) . super_predicates_of ( bound. def_id ( ) ) ;
711
727
}
@@ -2007,10 +2023,10 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(
2007
2023
}
2008
2024
}
2009
2025
2010
- /// Converts a specific GenericBound from the AST into a set of
2026
+ /// Converts a specific ` GenericBound` from the AST into a set of
2011
2027
/// 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`
2014
2030
/// and `<T as Bar>::X == i32`).
2015
2031
fn predicates_from_bound < ' tcx > (
2016
2032
astconv : & dyn AstConv < ' tcx , ' tcx > ,
0 commit comments