@@ -887,8 +887,13 @@ where
887
887
}
888
888
}
889
889
890
- let mut folder =
891
- ReplaceProjectionWith { ecx, param_env, mapping : replace_projection_with, nested : vec ! [ ] } ;
890
+ let mut folder = ReplaceProjectionWith {
891
+ ecx,
892
+ param_env,
893
+ mapping : replace_projection_with,
894
+ self_ty : trait_ref. self_ty ( ) ,
895
+ nested : vec ! [ ] ,
896
+ } ;
892
897
let folded_requirements = requirements. fold_with ( & mut folder) ;
893
898
894
899
folder
@@ -902,6 +907,7 @@ struct ReplaceProjectionWith<'a, D: SolverDelegate<Interner = I>, I: Interner> {
902
907
ecx : & ' a EvalCtxt < ' a , D > ,
903
908
param_env : I :: ParamEnv ,
904
909
mapping : HashMap < I :: DefId , ty:: Binder < I , ty:: ProjectionPredicate < I > > > ,
910
+ self_ty : I :: Ty ,
905
911
nested : Vec < Goal < I , I :: Predicate > > ,
906
912
}
907
913
@@ -914,29 +920,28 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I>
914
920
915
921
fn fold_ty ( & mut self , ty : I :: Ty ) -> I :: Ty {
916
922
if let ty:: Alias ( ty:: Projection , alias_ty) = ty. kind ( ) {
917
- if let Some ( replacement ) = self . mapping . get ( & alias_ty . def_id ) {
918
- // We may have a case where our object type's projection bound is higher-ranked,
919
- // but the where clauses we instantiated are not. We can solve this by instantiating
920
- // the binder at the usage site.
921
- let proj = self . ecx . instantiate_binder_with_infer ( * replacement ) ;
922
- // FIXME: Technically this equate could be fallible...
923
- self . nested . extend (
924
- self . ecx
925
- . eq_and_get_goals (
926
- self . param_env ,
927
- alias_ty ,
928
- proj . projection_term . expect_ty ( self . ecx . cx ( ) ) ,
929
- )
930
- . expect (
931
- "expected to be able to unify goal projection with dyn's projection" ,
932
- ) ,
933
- ) ;
934
- proj . term . expect_ty ( )
935
- } else {
936
- ty . super_fold_with ( self )
923
+ if alias_ty . self_ty ( ) == self . self_ty {
924
+ if let Some ( replacement ) = self . mapping . get ( & alias_ty . def_id ) {
925
+ // We may have a case where our object type's projection bound is higher-ranked,
926
+ // but the where clauses we instantiated are not. We can solve this by instantiating
927
+ // the binder at the usage site.
928
+ let proj = self . ecx . instantiate_binder_with_infer ( * replacement ) ;
929
+ // FIXME: Technically this equate could be fallible...
930
+ self . nested . extend (
931
+ self . ecx
932
+ . eq_and_get_goals (
933
+ self . param_env ,
934
+ alias_ty ,
935
+ proj . projection_term . expect_ty ( self . ecx . cx ( ) ) ,
936
+ )
937
+ . expect (
938
+ "expected to be able to unify goal projection with dyn's projection" ,
939
+ ) ,
940
+ ) ;
941
+ return proj . term . expect_ty ( ) ;
942
+ }
937
943
}
938
- } else {
939
- ty. super_fold_with ( self )
940
944
}
945
+ ty. super_fold_with ( self )
941
946
}
942
947
}
0 commit comments