@@ -54,6 +54,8 @@ use rustc_hash::{FxHashMap, FxHashSet};
54
54
use stdx:: { always, never} ;
55
55
use triomphe:: Arc ;
56
56
57
+ use crate :: next_solver:: DbInterner ;
58
+ use crate :: next_solver:: mapping:: NextSolverToChalk ;
57
59
use crate :: {
58
60
AliasEq , AliasTy , Binders , ClosureId , Const , DomainGoal , GenericArg , ImplTraitId , ImplTraitIdx ,
59
61
IncorrectGenericsLenKind , Interner , Lifetime , OpaqueTyId , ParamLoweringMode ,
@@ -922,13 +924,15 @@ impl<'db> InferenceContext<'db> {
922
924
} ) ;
923
925
diagnostics. shrink_to_fit ( ) ;
924
926
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 ( ) ) ;
926
929
* has_errors =
927
930
* has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
928
931
}
929
932
method_resolutions. shrink_to_fit ( ) ;
930
933
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 ( ) ) ;
932
936
* has_errors =
933
937
* has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
934
938
}
@@ -946,7 +950,12 @@ impl<'db> InferenceContext<'db> {
946
950
result. tuple_field_access_types = tuple_field_accesses_rev
947
951
. into_iter ( )
948
952
. 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
+ } )
950
959
. inspect ( |( _, subst) | {
951
960
* has_errors =
952
961
* has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
@@ -1015,14 +1024,12 @@ impl<'db> InferenceContext<'db> {
1015
1024
if let Some ( self_param) = self . body . self_param
1016
1025
&& let Some ( ty) = param_tys. next ( )
1017
1026
{
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) ;
1020
1028
self . write_binding_ty ( self_param, ty) ;
1021
1029
}
1022
1030
let mut tait_candidates = FxHashSet :: default ( ) ;
1023
1031
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) ;
1026
1033
1027
1034
self . infer_top_pat ( * pat, & ty, None ) ;
1028
1035
if ty
@@ -1073,7 +1080,7 @@ impl<'db> InferenceContext<'db> {
1073
1080
None => self . result . standard_types . unit . clone ( ) ,
1074
1081
} ;
1075
1082
1076
- self . return_ty = self . normalize_associated_types_in ( return_ty) ;
1083
+ self . return_ty = self . process_user_written_ty ( return_ty) ;
1077
1084
self . return_coercion = Some ( CoerceMany :: new ( self . return_ty . clone ( ) ) ) ;
1078
1085
1079
1086
// Functions might be defining usage sites of TAITs.
@@ -1415,8 +1422,7 @@ impl<'db> InferenceContext<'db> {
1415
1422
) -> Ty {
1416
1423
let ty = self
1417
1424
. 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)
1420
1426
}
1421
1427
1422
1428
fn make_body_ty ( & mut self , type_ref : TypeRefId ) -> Ty {
@@ -1562,15 +1568,35 @@ impl<'db> InferenceContext<'db> {
1562
1568
ty
1563
1569
}
1564
1570
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
+
1565
1590
/// Recurses through the given type, normalizing associated types mentioned
1566
1591
/// in it by replacing them by type variables and registering obligations to
1567
1592
/// resolve later. This should be done once for every type we get from some
1568
1593
/// type annotation (e.g. from a let type annotation, field type or function
1569
1594
/// call). `make_ty` handles this already, but e.g. for field types we need
1570
1595
/// 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
1572
1597
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 > > ,
1574
1600
{
1575
1601
self . table . normalize_associated_types_in ( ty)
1576
1602
}
0 commit comments