@@ -56,6 +56,9 @@ use std::slice;
5656#[ derive( Debug ) ]
5757pub struct PathSeg ( pub DefId , pub usize ) ;
5858
59+ #[ derive( Copy , Clone , Debug ) ]
60+ pub struct OnlySelfBounds ( pub bool ) ;
61+
5962pub trait AstConv < ' tcx > {
6063 fn tcx ( & self ) -> TyCtxt < ' tcx > ;
6164
@@ -670,6 +673,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
670673 args : & GenericArgs < ' _ > ,
671674 infer_args : bool ,
672675 self_ty : Ty < ' tcx > ,
676+ only_self_bounds : OnlySelfBounds ,
673677 ) -> GenericArgCountResult {
674678 let ( substs, arg_count) = self . create_substs_for_ast_path (
675679 trait_ref_span,
@@ -706,6 +710,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
706710 & mut dup_bindings,
707711 binding_span. unwrap_or ( binding. span ) ,
708712 constness,
713+ only_self_bounds,
709714 ) ;
710715 // Okay to ignore `Err` because of `ErrorGuaranteed` (see above).
711716 }
@@ -741,6 +746,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
741746 self_ty : Ty < ' tcx > ,
742747 bounds : & mut Bounds < ' tcx > ,
743748 speculative : bool ,
749+ only_self_bounds : OnlySelfBounds ,
744750 ) -> GenericArgCountResult {
745751 let hir_id = trait_ref. hir_ref_id ;
746752 let binding_span = None ;
@@ -766,6 +772,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
766772 args,
767773 infer_args,
768774 self_ty,
775+ only_self_bounds,
769776 )
770777 }
771778
@@ -777,6 +784,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
777784 args : & GenericArgs < ' _ > ,
778785 self_ty : Ty < ' tcx > ,
779786 bounds : & mut Bounds < ' tcx > ,
787+ only_self_bounds : OnlySelfBounds ,
780788 ) {
781789 let binding_span = Some ( span) ;
782790 let constness = ty:: BoundConstness :: NotConst ;
@@ -799,6 +807,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
799807 args,
800808 infer_args,
801809 self_ty,
810+ only_self_bounds,
802811 ) ;
803812 }
804813
@@ -947,6 +956,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
947956 ast_bounds : I ,
948957 bounds : & mut Bounds < ' tcx > ,
949958 bound_vars : & ' tcx ty:: List < ty:: BoundVariableKind > ,
959+ only_self_bounds : OnlySelfBounds ,
950960 ) {
951961 for ast_bound in ast_bounds {
952962 match ast_bound {
@@ -964,11 +974,18 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
964974 param_ty,
965975 bounds,
966976 false ,
977+ only_self_bounds,
967978 ) ;
968979 }
969980 & hir:: GenericBound :: LangItemTrait ( lang_item, span, hir_id, args) => {
970981 self . instantiate_lang_item_trait_ref (
971- lang_item, span, hir_id, args, param_ty, bounds,
982+ lang_item,
983+ span,
984+ hir_id,
985+ args,
986+ param_ty,
987+ bounds,
988+ only_self_bounds,
972989 ) ;
973990 }
974991 hir:: GenericBound :: Outlives ( lifetime) => {
@@ -1006,8 +1023,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10061023 & self ,
10071024 param_ty : Ty < ' tcx > ,
10081025 ast_bounds : & [ hir:: GenericBound < ' _ > ] ,
1026+ only_self_bounds : OnlySelfBounds ,
10091027 ) -> Bounds < ' tcx > {
1010- self . compute_bounds_inner ( param_ty, ast_bounds)
1028+ let mut bounds = Bounds :: default ( ) ;
1029+ self . add_bounds (
1030+ param_ty,
1031+ ast_bounds. iter ( ) ,
1032+ & mut bounds,
1033+ ty:: List :: empty ( ) ,
1034+ only_self_bounds,
1035+ ) ;
1036+ debug ! ( ?bounds) ;
1037+
1038+ bounds
10111039 }
10121040
10131041 /// Convert the bounds in `ast_bounds` that refer to traits which define an associated type
@@ -1029,17 +1057,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10291057 }
10301058 }
10311059
1032- self . compute_bounds_inner ( param_ty, & result)
1033- }
1034-
1035- fn compute_bounds_inner (
1036- & self ,
1037- param_ty : Ty < ' tcx > ,
1038- ast_bounds : & [ hir:: GenericBound < ' _ > ] ,
1039- ) -> Bounds < ' tcx > {
10401060 let mut bounds = Bounds :: default ( ) ;
1041-
1042- self . add_bounds ( param_ty, ast_bounds. iter ( ) , & mut bounds, ty:: List :: empty ( ) ) ;
1061+ self . add_bounds (
1062+ param_ty,
1063+ result. iter ( ) ,
1064+ & mut bounds,
1065+ ty:: List :: empty ( ) ,
1066+ OnlySelfBounds ( true ) ,
1067+ ) ;
10431068 debug ! ( ?bounds) ;
10441069
10451070 bounds
@@ -1062,6 +1087,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10621087 dup_bindings : & mut FxHashMap < DefId , Span > ,
10631088 path_span : Span ,
10641089 constness : ty:: BoundConstness ,
1090+ only_self_bounds : OnlySelfBounds ,
10651091 ) -> Result < ( ) , ErrorGuaranteed > {
10661092 // Given something like `U: SomeTrait<T = X>`, we want to produce a
10671093 // predicate like `<U as SomeTrait>::T = X`. This is somewhat
@@ -1361,8 +1387,20 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13611387 //
13621388 // Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty`
13631389 // parameter to have a skipped binder.
1364- let param_ty = tcx. mk_alias ( ty:: Projection , projection_ty. skip_binder ( ) ) ;
1365- self . add_bounds ( param_ty, ast_bounds. iter ( ) , bounds, projection_ty. bound_vars ( ) ) ;
1390+ //
1391+ // NOTE: If `only_self_bounds` is true, do NOT expand this associated
1392+ // type bound into a trait predicate, since we only want to add predicates
1393+ // for the `Self` type.
1394+ if !only_self_bounds. 0 {
1395+ let param_ty = tcx. mk_alias ( ty:: Projection , projection_ty. skip_binder ( ) ) ;
1396+ self . add_bounds (
1397+ param_ty,
1398+ ast_bounds. iter ( ) ,
1399+ bounds,
1400+ projection_ty. bound_vars ( ) ,
1401+ only_self_bounds,
1402+ ) ;
1403+ }
13661404 }
13671405 }
13681406 Ok ( ( ) )
@@ -1403,6 +1441,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14031441 dummy_self,
14041442 & mut bounds,
14051443 false ,
1444+ // FIXME: This should be `true`, but we don't really handle
1445+ // associated type bounds or type aliases in objects in a way
1446+ // that makes this meaningful, I think.
1447+ OnlySelfBounds ( false ) ,
14061448 ) {
14071449 potential_assoc_types. extend ( cur_potential_assoc_types) ;
14081450 }
0 commit comments