@@ -11,39 +11,35 @@ use hir_def::{AdtId, lang_item::LangItem};
11
11
use hir_expand:: name:: Name ;
12
12
use intern:: sym;
13
13
use rustc_hash:: { FxHashMap , FxHashSet } ;
14
- use rustc_type_ir:: inherent:: Ty as _;
15
14
use rustc_type_ir:: {
16
- FloatVid , IntVid , TyVid , TypeVisitableExt ,
17
- inherent:: { IntoKind , Span , Term as _} ,
15
+ FloatVid , IntVid , TyVid , TypeVisitableExt , UpcastFrom ,
16
+ inherent:: { IntoKind , Span , Term as _, Ty as _ } ,
18
17
relate:: { Relate , solver_relating:: RelateExt } ,
19
- solve:: { Certainty , GoalSource , NoSolution } ,
18
+ solve:: { Certainty , GoalSource } ,
20
19
} ;
21
20
use smallvec:: SmallVec ;
22
21
use triomphe:: Arc ;
23
22
24
23
use super :: { InferResult , InferenceContext , TypeError } ;
25
- use crate :: next_solver:: ErrorGuaranteed ;
26
24
use crate :: {
27
25
AliasTy , BoundVar , Canonical , Const , ConstValue , DebruijnIndex , GenericArg , GenericArgData ,
28
- Goal , GoalData , InEnvironment , InferenceVar , Interner , Lifetime , OpaqueTyId , ParamKind ,
29
- ProjectionTy , Scalar , Substitution , TraitEnvironment , TraitRef , Ty , TyBuilder , TyExt , TyKind ,
30
- VariableKind , WhereClause ,
26
+ InferenceVar , Interner , Lifetime , OpaqueTyId , ProjectionTy , Scalar , Substitution ,
27
+ TraitEnvironment , Ty , TyExt , TyKind , VariableKind ,
31
28
consteval:: unknown_const,
32
29
db:: HirDatabase ,
33
30
fold_generic_args, fold_tys_and_consts,
34
- next_solver:: infer:: InferOk ,
35
31
next_solver:: {
36
- self , ClauseKind , DbInterner , ParamEnv , Predicate , PredicateKind , SolverDefIds , Term ,
32
+ self , ClauseKind , DbInterner , ErrorGuaranteed , ParamEnv , Predicate , PredicateKind ,
33
+ SolverDefIds , Term , TraitRef ,
37
34
fulfill:: FulfillmentCtxt ,
38
35
infer:: {
39
- DbInternerInferExt , InferCtxt ,
36
+ DbInternerInferExt , InferCtxt , InferOk ,
40
37
snapshot:: CombinedSnapshot ,
41
38
traits:: { Obligation , ObligationCause } ,
42
39
} ,
43
40
inspect:: { InspectConfig , InspectGoal , ProofTreeVisitor } ,
44
41
mapping:: { ChalkToNextSolver , NextSolverToChalk } ,
45
42
} ,
46
- to_chalk_trait_id,
47
43
traits:: {
48
44
FnTrait , NextTraitSolveResult , next_trait_solve_canonical_in_ctxt, next_trait_solve_in_ctxt,
49
45
} ,
@@ -877,26 +873,15 @@ impl<'db> InferenceTable<'db> {
877
873
/// whether a trait *might* be implemented before deciding to 'lock in' the
878
874
/// choice (during e.g. method resolution or deref).
879
875
#[ tracing:: instrument( level = "debug" , skip( self ) ) ]
880
- pub ( crate ) fn try_obligation ( & mut self , goal : Goal ) -> NextTraitSolveResult {
881
- let in_env = InEnvironment :: new ( & self . trait_env . env , goal ) ;
882
- let canonicalized = self . canonicalize ( in_env . to_nextsolver ( self . interner ) ) ;
876
+ pub ( crate ) fn try_obligation ( & mut self , predicate : Predicate < ' db > ) -> NextTraitSolveResult {
877
+ let goal = next_solver :: Goal { param_env : self . param_env , predicate } ;
878
+ let canonicalized = self . canonicalize ( goal ) ;
883
879
884
880
next_trait_solve_canonical_in_ctxt ( & self . infer_ctxt , canonicalized)
885
881
}
886
882
887
- #[ tracing:: instrument( level = "debug" , skip( self ) ) ]
888
- pub ( crate ) fn solve_obligation ( & mut self , goal : Goal ) -> Result < Certainty , NoSolution > {
889
- let goal = InEnvironment :: new ( & self . trait_env . env , goal) ;
890
- let goal = goal. to_nextsolver ( self . interner ) ;
891
- let result = next_trait_solve_in_ctxt ( & self . infer_ctxt , goal) ;
892
- result. map ( |m| m. 1 )
893
- }
894
-
895
883
pub ( crate ) fn register_obligation ( & mut self , predicate : Predicate < ' db > ) {
896
- let goal = next_solver:: Goal {
897
- param_env : self . trait_env . env . to_nextsolver ( self . interner ) ,
898
- predicate,
899
- } ;
884
+ let goal = next_solver:: Goal { param_env : self . param_env , predicate } ;
900
885
self . register_obligation_in_env ( goal)
901
886
}
902
887
@@ -984,7 +969,7 @@ impl<'db> InferenceTable<'db> {
984
969
& mut self ,
985
970
ty : & Ty ,
986
971
num_args : usize ,
987
- ) -> Option < ( FnTrait , Vec < crate :: next_solver:: Ty < ' db > > , crate :: next_solver:: Ty < ' db > ) > {
972
+ ) -> Option < ( FnTrait , Vec < next_solver:: Ty < ' db > > , next_solver:: Ty < ' db > ) > {
988
973
for ( fn_trait_name, output_assoc_name, subtraits) in [
989
974
( FnTrait :: FnOnce , sym:: Output , & [ FnTrait :: Fn , FnTrait :: FnMut ] [ ..] ) ,
990
975
( FnTrait :: AsyncFnMut , sym:: CallRefFuture , & [ FnTrait :: AsyncFn ] ) ,
@@ -997,42 +982,34 @@ impl<'db> InferenceTable<'db> {
997
982
trait_data. associated_type_by_name ( & Name :: new_symbol_root ( output_assoc_name) ) ?;
998
983
999
984
let mut arg_tys = Vec :: with_capacity ( num_args) ;
1000
- let arg_ty = TyBuilder :: tuple ( num_args)
1001
- . fill ( |it| {
1002
- let arg = match it {
1003
- ParamKind :: Type => self . new_type_var ( ) ,
1004
- ParamKind :: Lifetime => unreachable ! ( "Tuple with lifetime parameter" ) ,
1005
- ParamKind :: Const ( _) => unreachable ! ( "Tuple with const parameter" ) ,
1006
- } ;
1007
- arg_tys. push ( arg. to_nextsolver ( self . interner ) ) ;
1008
- arg. cast ( Interner )
985
+ let arg_ty = next_solver:: Ty :: new_tup_from_iter (
986
+ self . interner ,
987
+ std:: iter:: repeat_with ( || {
988
+ let ty = self . next_ty_var ( ) ;
989
+ arg_tys. push ( ty) ;
990
+ ty
1009
991
} )
1010
- . build ( ) ;
1011
-
1012
- let b = TyBuilder :: trait_ref ( self . db , fn_trait) ;
1013
- if b. remaining ( ) != 2 {
1014
- return None ;
1015
- }
1016
- let mut trait_ref = b. push ( ty. clone ( ) ) . push ( arg_ty) . build ( ) ;
1017
-
1018
- let projection = TyBuilder :: assoc_type_projection (
1019
- self . db ,
1020
- output_assoc_type,
1021
- Some ( trait_ref. substitution . clone ( ) ) ,
1022
- )
1023
- . fill_with_unknown ( )
1024
- . build ( ) ;
1025
-
1026
- let goal: Goal = trait_ref. clone ( ) . cast ( Interner ) ;
1027
- if !self . try_obligation ( goal. clone ( ) ) . no_solution ( ) {
1028
- self . register_obligation ( goal. to_nextsolver ( self . interner ) ) ;
1029
- let return_ty =
1030
- self . normalize_projection_ty ( projection) . to_nextsolver ( self . interner ) ;
992
+ . take ( num_args) ,
993
+ ) ;
994
+ let args = [ ty. to_nextsolver ( self . interner ) , arg_ty] ;
995
+ let trait_ref = crate :: next_solver:: TraitRef :: new ( self . interner , fn_trait. into ( ) , args) ;
996
+
997
+ let projection = crate :: next_solver:: Ty :: new_alias (
998
+ self . interner ,
999
+ rustc_type_ir:: AliasTyKind :: Projection ,
1000
+ crate :: next_solver:: AliasTy :: new ( self . interner , output_assoc_type. into ( ) , args) ,
1001
+ ) ;
1002
+
1003
+ let pred = crate :: next_solver:: Predicate :: upcast_from ( trait_ref, self . interner ) ;
1004
+ if !self . try_obligation ( pred) . no_solution ( ) {
1005
+ self . register_obligation ( pred) ;
1006
+ let return_ty = self . normalize_alias_ty ( projection) ;
1031
1007
for & fn_x in subtraits {
1032
1008
let fn_x_trait = fn_x. get_id ( self . db , krate) ?;
1033
- trait_ref. trait_id = to_chalk_trait_id ( fn_x_trait) ;
1034
- let goal = trait_ref. clone ( ) . cast ( Interner ) ;
1035
- if !self . try_obligation ( goal) . no_solution ( ) {
1009
+ let trait_ref =
1010
+ crate :: next_solver:: TraitRef :: new ( self . interner , fn_x_trait. into ( ) , args) ;
1011
+ let pred = crate :: next_solver:: Predicate :: upcast_from ( trait_ref, self . interner ) ;
1012
+ if !self . try_obligation ( pred) . no_solution ( ) {
1036
1013
return Some ( ( fn_x, arg_tys, return_ty) ) ;
1037
1014
}
1038
1015
}
@@ -1171,12 +1148,11 @@ impl<'db> InferenceTable<'db> {
1171
1148
let Some ( sized) = LangItem :: Sized . resolve_trait ( self . db , self . trait_env . krate ) else {
1172
1149
return false ;
1173
1150
} ;
1174
- let sized_pred = WhereClause :: Implemented ( TraitRef {
1175
- trait_id : to_chalk_trait_id ( sized) ,
1176
- substitution : Substitution :: from1 ( Interner , ty) ,
1177
- } ) ;
1178
- let goal = GoalData :: DomainGoal ( chalk_ir:: DomainGoal :: Holds ( sized_pred) ) . intern ( Interner ) ;
1179
- self . try_obligation ( goal) . certain ( )
1151
+ let sized_pred = Predicate :: upcast_from (
1152
+ TraitRef :: new ( self . interner , sized. into ( ) , [ ty. to_nextsolver ( self . interner ) ] ) ,
1153
+ self . interner ,
1154
+ ) ;
1155
+ self . try_obligation ( sized_pred) . certain ( )
1180
1156
}
1181
1157
}
1182
1158
0 commit comments