@@ -835,11 +835,7 @@ impl<'a> InferenceContext<'a> {
835
835
let return_ty = if let Some ( rpits) = self . db . return_type_impl_traits ( func) {
836
836
// RPIT opaque types use substitution of their parent function.
837
837
let fn_placeholders = TyBuilder :: placeholder_subst ( self . db , func) ;
838
- let result = self . insert_inference_vars_for_impl_trait (
839
- return_ty,
840
- rpits. clone ( ) ,
841
- fn_placeholders,
842
- ) ;
838
+ let result = self . insert_inference_vars_for_impl_trait ( return_ty, fn_placeholders) ;
843
839
let rpits = rpits. skip_binders ( ) ;
844
840
for ( id, _) in rpits. impl_traits . iter ( ) {
845
841
if let Entry :: Vacant ( e) = self . result . type_of_rpit . entry ( id) {
@@ -862,12 +858,7 @@ impl<'a> InferenceContext<'a> {
862
858
self . insert_atpit_coercion_table ( params_and_ret_tys. iter ( ) ) ;
863
859
}
864
860
865
- fn insert_inference_vars_for_impl_trait < T > (
866
- & mut self ,
867
- t : T ,
868
- rpits : Arc < chalk_ir:: Binders < crate :: ImplTraits > > ,
869
- placeholders : Substitution ,
870
- ) -> T
861
+ fn insert_inference_vars_for_impl_trait < T > ( & mut self , t : T , placeholders : Substitution ) -> T
871
862
where
872
863
T : crate :: HasInterner < Interner = Interner > + crate :: TypeFoldable < Interner > ,
873
864
{
@@ -878,25 +869,30 @@ impl<'a> InferenceContext<'a> {
878
869
TyKind :: OpaqueType ( opaque_ty_id, _) => * opaque_ty_id,
879
870
_ => return ty,
880
871
} ;
881
- let idx = match self . db . lookup_intern_impl_trait_id ( opaque_ty_id. into ( ) ) {
882
- ImplTraitId :: ReturnTypeImplTrait ( _, idx) => idx,
883
- ImplTraitId :: AssociatedTypeImplTrait ( _, idx) => idx,
884
- _ => unreachable ! ( ) ,
872
+ let ( impl_traits, idx) =
873
+ match self . db . lookup_intern_impl_trait_id ( opaque_ty_id. into ( ) ) {
874
+ ImplTraitId :: ReturnTypeImplTrait ( def, idx) => {
875
+ ( self . db . return_type_impl_traits ( def) , idx)
876
+ }
877
+ ImplTraitId :: AssociatedTypeImplTrait ( def, idx) => {
878
+ ( self . db . type_alias_impl_traits ( def) , idx)
879
+ }
880
+ _ => unreachable ! ( ) ,
881
+ } ;
882
+ let Some ( impl_traits) = impl_traits else {
883
+ return ty;
885
884
} ;
886
- let bounds =
887
- ( * rpits ) . map_ref ( |rpits| rpits. impl_traits [ idx] . bounds . map_ref ( |it| it. iter ( ) ) ) ;
885
+ let bounds = ( * impl_traits )
886
+ . map_ref ( |rpits| rpits. impl_traits [ idx] . bounds . map_ref ( |it| it. iter ( ) ) ) ;
888
887
let var = self . table . new_type_var ( ) ;
889
888
let var_subst = Substitution :: from1 ( Interner , var. clone ( ) ) ;
890
889
for bound in bounds {
891
890
let predicate = bound. map ( |it| it. cloned ( ) ) . substitute ( Interner , & placeholders) ;
892
891
let ( var_predicate, binders) =
893
892
predicate. substitute ( Interner , & var_subst) . into_value_and_skipped_binders ( ) ;
894
893
always ! ( binders. is_empty( Interner ) ) ; // quantified where clauses not yet handled
895
- let var_predicate = self . insert_inference_vars_for_impl_trait (
896
- var_predicate,
897
- rpits. clone ( ) ,
898
- placeholders. clone ( ) ,
899
- ) ;
894
+ let var_predicate = self
895
+ . insert_inference_vars_for_impl_trait ( var_predicate, placeholders. clone ( ) ) ;
900
896
self . push_obligation ( var_predicate. cast ( Interner ) ) ;
901
897
}
902
898
self . result . type_of_rpit . insert ( idx, var. clone ( ) ) ;
@@ -983,16 +979,8 @@ impl<'a> InferenceContext<'a> {
983
979
self . db . lookup_intern_impl_trait_id ( opaque_ty_id. into ( ) )
984
980
{
985
981
if assoc_tys. contains ( & alias_id) {
986
- let atpits = self
987
- . db
988
- . type_alias_impl_traits ( alias_id)
989
- . expect ( "Marked as ATPIT but no impl traits!" ) ;
990
982
let alias_placeholders = TyBuilder :: placeholder_subst ( self . db , alias_id) ;
991
- let ty = self . insert_inference_vars_for_impl_trait (
992
- ty,
993
- atpits,
994
- alias_placeholders,
995
- ) ;
983
+ let ty = self . insert_inference_vars_for_impl_trait ( ty, alias_placeholders) ;
996
984
return Some ( ( opaque_ty_id, ty) ) ;
997
985
}
998
986
}
0 commit comments