@@ -54,6 +54,8 @@ use rustc_hash::{FxHashMap, FxHashSet};
5454use stdx:: { always, never} ;
5555use triomphe:: Arc ;
5656
57+ use crate :: next_solver:: DbInterner ;
58+ use crate :: next_solver:: mapping:: NextSolverToChalk ;
5759use crate :: {
5860 AliasEq , AliasTy , Binders , ClosureId , Const , DomainGoal , GenericArg , ImplTraitId , ImplTraitIdx ,
5961 IncorrectGenericsLenKind , Interner , Lifetime , OpaqueTyId , ParamLoweringMode ,
@@ -922,13 +924,15 @@ impl<'db> InferenceContext<'db> {
922924 } ) ;
923925 diagnostics. shrink_to_fit ( ) ;
924926 for ( _, subst) in method_resolutions. values_mut ( ) {
925- * subst = table. resolve_completely ( subst. clone ( ) ) ;
927+ * subst =
928+ table. resolve_completely :: < _ , crate :: next_solver:: GenericArgs < ' db > > ( subst. clone ( ) ) ;
926929 * has_errors =
927930 * has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
928931 }
929932 method_resolutions. shrink_to_fit ( ) ;
930933 for ( _, subst) in assoc_resolutions. values_mut ( ) {
931- * subst = table. resolve_completely ( subst. clone ( ) ) ;
934+ * subst =
935+ table. resolve_completely :: < _ , crate :: next_solver:: GenericArgs < ' db > > ( subst. clone ( ) ) ;
932936 * has_errors =
933937 * has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
934938 }
@@ -946,7 +950,12 @@ impl<'db> InferenceContext<'db> {
946950 result. tuple_field_access_types = tuple_field_accesses_rev
947951 . into_iter ( )
948952 . enumerate ( )
949- . map ( |( idx, subst) | ( TupleId ( idx as u32 ) , table. resolve_completely ( subst) ) )
953+ . map ( |( idx, subst) | {
954+ (
955+ TupleId ( idx as u32 ) ,
956+ table. resolve_completely :: < _ , crate :: next_solver:: GenericArgs < ' db > > ( subst) ,
957+ )
958+ } )
950959 . inspect ( |( _, subst) | {
951960 * has_errors =
952961 * has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
@@ -1015,14 +1024,12 @@ impl<'db> InferenceContext<'db> {
10151024 if let Some ( self_param) = self . body . self_param
10161025 && let Some ( ty) = param_tys. next ( )
10171026 {
1018- let ty = self . insert_type_vars ( ty) ;
1019- let ty = self . normalize_associated_types_in ( ty) ;
1027+ let ty = self . process_user_written_ty ( ty) ;
10201028 self . write_binding_ty ( self_param, ty) ;
10211029 }
10221030 let mut tait_candidates = FxHashSet :: default ( ) ;
10231031 for ( ty, pat) in param_tys. zip ( & * self . body . params ) {
1024- let ty = self . insert_type_vars ( ty) ;
1025- let ty = self . normalize_associated_types_in ( ty) ;
1032+ let ty = self . process_user_written_ty ( ty) ;
10261033
10271034 self . infer_top_pat ( * pat, & ty, None ) ;
10281035 if ty
@@ -1073,7 +1080,7 @@ impl<'db> InferenceContext<'db> {
10731080 None => self . result . standard_types . unit . clone ( ) ,
10741081 } ;
10751082
1076- self . return_ty = self . normalize_associated_types_in ( return_ty) ;
1083+ self . return_ty = self . process_user_written_ty ( return_ty) ;
10771084 self . return_coercion = Some ( CoerceMany :: new ( self . return_ty . clone ( ) ) ) ;
10781085
10791086 // Functions might be defining usage sites of TAITs.
@@ -1415,8 +1422,7 @@ impl<'db> InferenceContext<'db> {
14151422 ) -> Ty {
14161423 let ty = self
14171424 . with_ty_lowering ( store, type_source, lifetime_elision, |ctx| ctx. lower_ty ( type_ref) ) ;
1418- let ty = self . insert_type_vars ( ty) ;
1419- self . normalize_associated_types_in ( ty)
1425+ self . process_user_written_ty ( ty)
14201426 }
14211427
14221428 fn make_body_ty ( & mut self , type_ref : TypeRefId ) -> Ty {
@@ -1562,15 +1568,35 @@ impl<'db> InferenceContext<'db> {
15621568 ty
15631569 }
15641570
1571+ /// Whenever you lower a user-written type, you should call this.
1572+ fn process_user_written_ty < T , U > ( & mut self , ty : T ) -> T
1573+ where
1574+ T : HasInterner < Interner = Interner > + TypeFoldable < Interner > + ChalkToNextSolver < ' db , U > ,
1575+ U : NextSolverToChalk < ' db , T > + rustc_type_ir:: TypeFoldable < DbInterner < ' db > > ,
1576+ {
1577+ self . table . process_user_written_ty ( ty)
1578+ }
1579+
1580+ /// The difference of this method from `process_user_written_ty()` is that this method doesn't register a well-formed obligation,
1581+ /// while `process_user_written_ty()` should (but doesn't currently).
1582+ fn process_remote_user_written_ty < T , U > ( & mut self , ty : T ) -> T
1583+ where
1584+ T : HasInterner < Interner = Interner > + TypeFoldable < Interner > + ChalkToNextSolver < ' db , U > ,
1585+ U : NextSolverToChalk < ' db , T > + rustc_type_ir:: TypeFoldable < DbInterner < ' db > > ,
1586+ {
1587+ self . table . process_remote_user_written_ty ( ty)
1588+ }
1589+
15651590 /// Recurses through the given type, normalizing associated types mentioned
15661591 /// in it by replacing them by type variables and registering obligations to
15671592 /// resolve later. This should be done once for every type we get from some
15681593 /// type annotation (e.g. from a let type annotation, field type or function
15691594 /// call). `make_ty` handles this already, but e.g. for field types we need
15701595 /// to do it as well.
1571- fn normalize_associated_types_in < T > ( & mut self , ty : T ) -> T
1596+ fn normalize_associated_types_in < T , U > ( & mut self , ty : T ) -> T
15721597 where
1573- T : HasInterner < Interner = Interner > + TypeFoldable < Interner > ,
1598+ T : HasInterner < Interner = Interner > + TypeFoldable < Interner > + ChalkToNextSolver < ' db , U > ,
1599+ U : NextSolverToChalk < ' db , T > + rustc_type_ir:: TypeFoldable < DbInterner < ' db > > ,
15741600 {
15751601 self . table . normalize_associated_types_in ( ty)
15761602 }
0 commit comments