@@ -1084,15 +1084,42 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1084
1084
where
1085
1085
I : Iterator < Item = ty:: PolyTraitRef < ' tcx > > ,
1086
1086
{
1087
- let mut matching_candidates = all_candidates ( ) . filter ( |r| {
1088
- self . trait_defines_associated_item_named ( r. def_id ( ) , ty:: AssocKind :: Type , assoc_name)
1089
- } ) ;
1090
- let mut const_candidates = all_candidates ( ) . filter ( |r| {
1091
- self . trait_defines_associated_item_named ( r. def_id ( ) , ty:: AssocKind :: Const , assoc_name)
1092
- } ) ;
1087
+ let mut matching_candidates = all_candidates ( )
1088
+ . filter ( |r| {
1089
+ self . trait_defines_associated_item_named (
1090
+ r. def_id ( ) ,
1091
+ ty:: AssocKind :: Type ,
1092
+ assoc_name,
1093
+ )
1094
+ } )
1095
+ // For the purposes of an associated type, we only care
1096
+ // about supertraits where the host effect is set to true.
1097
+ . filter ( |trait_ref| {
1098
+ let tcx = self . tcx ( ) ;
1099
+ let generics = tcx. generics_of ( trait_ref. def_id ( ) ) ;
1100
+ generics. host_effect_index . map_or ( true , |idx| {
1101
+ trait_ref. skip_binder ( ) . args . const_at ( idx) == tcx. consts . true_
1102
+ } )
1103
+ } ) ;
1104
+ let mut const_candidates = all_candidates ( )
1105
+ . filter ( |r| {
1106
+ self . trait_defines_associated_item_named (
1107
+ r. def_id ( ) ,
1108
+ ty:: AssocKind :: Const ,
1109
+ assoc_name,
1110
+ )
1111
+ } )
1112
+ // For the purposes of an associated const, we only care
1113
+ // about supertraits where the host effect is set to true.
1114
+ . filter ( |trait_ref| {
1115
+ let tcx = self . tcx ( ) ;
1116
+ let generics = tcx. generics_of ( trait_ref. def_id ( ) ) ;
1117
+ generics. host_effect_index . map_or ( true , |idx| {
1118
+ trait_ref. skip_binder ( ) . args . const_at ( idx) == tcx. consts . true_
1119
+ } )
1120
+ } ) ;
1093
1121
1094
- let ( mut bound, mut next_cand) = match ( matching_candidates. next ( ) , const_candidates. next ( ) )
1095
- {
1122
+ let ( bound, next_cand) = match ( matching_candidates. next ( ) , const_candidates. next ( ) ) {
1096
1123
( Some ( bound) , _) => ( bound, matching_candidates. next ( ) ) ,
1097
1124
( None , Some ( bound) ) => ( bound, const_candidates. next ( ) ) ,
1098
1125
( None , None ) => {
@@ -1108,37 +1135,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1108
1135
} ;
1109
1136
debug ! ( ?bound) ;
1110
1137
1111
- // look for a candidate that is not the same as our first bound, disregarding
1112
- // whether the bound is const.
1113
- while let Some ( mut bound2) = next_cand {
1114
- debug ! ( ?bound2) ;
1115
- let tcx = self . tcx ( ) ;
1116
- if bound2. bound_vars ( ) != bound. bound_vars ( ) {
1117
- break ;
1118
- }
1119
-
1120
- let generics = tcx. generics_of ( bound. def_id ( ) ) ;
1121
- let Some ( host_index) = generics. host_effect_index else { break } ;
1122
-
1123
- // always return the bound that contains the host param.
1124
- if let ty:: ConstKind :: Param ( _) = bound2. skip_binder ( ) . args . const_at ( host_index) . kind ( ) {
1125
- ( bound, bound2) = ( bound2, bound) ;
1126
- }
1127
-
1128
- let unconsted_args = bound
1129
- . skip_binder ( )
1130
- . args
1131
- . iter ( )
1132
- . enumerate ( )
1133
- . map ( |( n, arg) | if host_index == n { tcx. consts . true_ . into ( ) } else { arg } ) ;
1134
-
1135
- if unconsted_args. eq ( bound2. skip_binder ( ) . args . iter ( ) ) {
1136
- next_cand = matching_candidates. next ( ) . or_else ( || const_candidates. next ( ) ) ;
1137
- } else {
1138
- break ;
1139
- }
1140
- }
1141
-
1142
1138
if let Some ( bound2) = next_cand {
1143
1139
debug ! ( ?bound2) ;
1144
1140
@@ -1226,9 +1222,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1226
1222
assoc_name : Ident ,
1227
1223
span : Span ,
1228
1224
) -> Result < ty:: PolyTraitRef < ' tcx > , ErrorGuaranteed > {
1229
- let mut matching_candidates = all_candidates. filter ( |r| {
1230
- self . trait_defines_associated_item_named ( r. def_id ( ) , ty:: AssocKind :: Fn , assoc_name)
1231
- } ) ;
1225
+ let mut matching_candidates = all_candidates
1226
+ . filter ( |r| {
1227
+ self . trait_defines_associated_item_named ( r. def_id ( ) , ty:: AssocKind :: Fn , assoc_name)
1228
+ } )
1229
+ // For the purposes of an RTN bound, we only care
1230
+ // about supertraits where the host effect is set to true.
1231
+ . filter ( |trait_ref| {
1232
+ let tcx = self . tcx ( ) ;
1233
+ let generics = tcx. generics_of ( trait_ref. def_id ( ) ) ;
1234
+ generics. host_effect_index . map_or ( true , |idx| {
1235
+ trait_ref. skip_binder ( ) . args . const_at ( idx) == tcx. consts . true_
1236
+ } )
1237
+ } ) ;
1232
1238
1233
1239
let candidate = match matching_candidates. next ( ) {
1234
1240
Some ( candidate) => candidate,
0 commit comments