@@ -11,39 +11,35 @@ use hir_def::{AdtId, lang_item::LangItem};
1111use hir_expand:: name:: Name ;
1212use intern:: sym;
1313use rustc_hash:: { FxHashMap , FxHashSet } ;
14- use rustc_type_ir:: inherent:: Ty as _;
1514use 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 _ } ,
1817 relate:: { Relate , solver_relating:: RelateExt } ,
19- solve:: { Certainty , GoalSource , NoSolution } ,
18+ solve:: { Certainty , GoalSource } ,
2019} ;
2120use smallvec:: SmallVec ;
2221use triomphe:: Arc ;
2322
2423use super :: { InferResult , InferenceContext , TypeError } ;
25- use crate :: next_solver:: ErrorGuaranteed ;
2624use crate :: {
2725 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 ,
3128 consteval:: unknown_const,
3229 db:: HirDatabase ,
3330 fold_generic_args, fold_tys_and_consts,
34- next_solver:: infer:: InferOk ,
3531 next_solver:: {
36- self , ClauseKind , DbInterner , ParamEnv , Predicate , PredicateKind , SolverDefIds , Term ,
32+ self , ClauseKind , DbInterner , ErrorGuaranteed , ParamEnv , Predicate , PredicateKind ,
33+ SolverDefIds , Term , TraitRef ,
3734 fulfill:: FulfillmentCtxt ,
3835 infer:: {
39- DbInternerInferExt , InferCtxt ,
36+ DbInternerInferExt , InferCtxt , InferOk ,
4037 snapshot:: CombinedSnapshot ,
4138 traits:: { Obligation , ObligationCause } ,
4239 } ,
4340 inspect:: { InspectConfig , InspectGoal , ProofTreeVisitor } ,
4441 mapping:: { ChalkToNextSolver , NextSolverToChalk } ,
4542 } ,
46- to_chalk_trait_id,
4743 traits:: {
4844 FnTrait , NextTraitSolveResult , next_trait_solve_canonical_in_ctxt, next_trait_solve_in_ctxt,
4945 } ,
@@ -877,26 +873,15 @@ impl<'db> InferenceTable<'db> {
877873 /// whether a trait *might* be implemented before deciding to 'lock in' the
878874 /// choice (during e.g. method resolution or deref).
879875 #[ 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 ) ;
883879
884880 next_trait_solve_canonical_in_ctxt ( & self . infer_ctxt , canonicalized)
885881 }
886882
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-
895883 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 } ;
900885 self . register_obligation_in_env ( goal)
901886 }
902887
@@ -984,7 +969,7 @@ impl<'db> InferenceTable<'db> {
984969 & mut self ,
985970 ty : & Ty ,
986971 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 > ) > {
988973 for ( fn_trait_name, output_assoc_name, subtraits) in [
989974 ( FnTrait :: FnOnce , sym:: Output , & [ FnTrait :: Fn , FnTrait :: FnMut ] [ ..] ) ,
990975 ( FnTrait :: AsyncFnMut , sym:: CallRefFuture , & [ FnTrait :: AsyncFn ] ) ,
@@ -997,42 +982,34 @@ impl<'db> InferenceTable<'db> {
997982 trait_data. associated_type_by_name ( & Name :: new_symbol_root ( output_assoc_name) ) ?;
998983
999984 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
1009991 } )
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) ;
10311007 for & fn_x in subtraits {
10321008 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 ( ) {
10361013 return Some ( ( fn_x, arg_tys, return_ty) ) ;
10371014 }
10381015 }
@@ -1171,12 +1148,11 @@ impl<'db> InferenceTable<'db> {
11711148 let Some ( sized) = LangItem :: Sized . resolve_trait ( self . db , self . trait_env . krate ) else {
11721149 return false ;
11731150 } ;
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 ( )
11801156 }
11811157}
11821158
0 commit comments