@@ -27,9 +27,10 @@ use ra_prof::profile;
2727use test_utils:: tested_by;
2828
2929use super :: {
30- autoderef, method_resolution, op, primitive,
30+ autoderef, lower , method_resolution, op, primitive,
3131 traits:: { Guidance , Obligation , ProjectionPredicate , Solution } ,
32- ApplicationTy , CallableDef , ProjectionTy , Substs , TraitRef , Ty , TypableDef , TypeCtor ,
32+ ApplicationTy , CallableDef , Environment , InEnvironment , ProjectionTy , Substs , TraitRef , Ty ,
33+ TypableDef , TypeCtor ,
3334} ;
3435use crate :: {
3536 adt:: VariantDef ,
@@ -165,6 +166,7 @@ struct InferenceContext<'a, D: HirDatabase> {
165166 body : Arc < Body > ,
166167 resolver : Resolver ,
167168 var_unification_table : InPlaceUnificationTable < TypeVarId > ,
169+ trait_env : Arc < Environment > ,
168170 obligations : Vec < Obligation > ,
169171 method_resolutions : FxHashMap < ExprId , Function > ,
170172 field_resolutions : FxHashMap < ExprId , StructField > ,
@@ -188,6 +190,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
188190 var_unification_table : InPlaceUnificationTable :: new ( ) ,
189191 obligations : Vec :: default ( ) ,
190192 return_ty : Ty :: Unknown , // set in collect_fn_signature
193+ trait_env : lower:: trait_env ( db, & resolver) ,
191194 db,
192195 body,
193196 resolver,
@@ -328,51 +331,25 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
328331 fn resolve_obligations_as_possible ( & mut self ) {
329332 let obligations = mem:: replace ( & mut self . obligations , Vec :: new ( ) ) ;
330333 for obligation in obligations {
331- match & obligation {
332- Obligation :: Trait ( tr) => {
333- let canonicalized = self . canonicalizer ( ) . canonicalize_trait_ref ( tr. clone ( ) ) ;
334- let solution = self
335- . db
336- . implements ( self . resolver . krate ( ) . unwrap ( ) , canonicalized. value . clone ( ) ) ;
337- match solution {
338- Some ( Solution :: Unique ( substs) ) => {
339- canonicalized. apply_solution ( self , substs. 0 ) ;
340- }
341- Some ( Solution :: Ambig ( Guidance :: Definite ( substs) ) ) => {
342- canonicalized. apply_solution ( self , substs. 0 ) ;
343- self . obligations . push ( obligation) ;
344- }
345- Some ( _) => {
346- // FIXME use this when trying to resolve everything at the end
347- self . obligations . push ( obligation) ;
348- }
349- None => {
350- // FIXME obligation cannot be fulfilled => diagnostic
351- }
352- } ;
334+ let in_env = InEnvironment :: new ( self . trait_env . clone ( ) , obligation. clone ( ) ) ;
335+ let canonicalized = self . canonicalizer ( ) . canonicalize_obligation ( in_env) ;
336+ let solution =
337+ self . db . solve ( self . resolver . krate ( ) . unwrap ( ) , canonicalized. value . clone ( ) ) ;
338+
339+ match solution {
340+ Some ( Solution :: Unique ( substs) ) => {
341+ canonicalized. apply_solution ( self , substs. 0 ) ;
353342 }
354- Obligation :: Projection ( pr) => {
355- let canonicalized = self . canonicalizer ( ) . canonicalize_projection ( pr. clone ( ) ) ;
356- let solution = self
357- . db
358- . normalize ( self . resolver . krate ( ) . unwrap ( ) , canonicalized. value . clone ( ) ) ;
359-
360- match solution {
361- Some ( Solution :: Unique ( substs) ) => {
362- canonicalized. apply_solution ( self , substs. 0 ) ;
363- }
364- Some ( Solution :: Ambig ( Guidance :: Definite ( substs) ) ) => {
365- canonicalized. apply_solution ( self , substs. 0 ) ;
366- self . obligations . push ( obligation) ;
367- }
368- Some ( _) => {
369- // FIXME use this when trying to resolve everything at the end
370- self . obligations . push ( obligation) ;
371- }
372- None => {
373- // FIXME obligation cannot be fulfilled => diagnostic
374- }
375- } ;
343+ Some ( Solution :: Ambig ( Guidance :: Definite ( substs) ) ) => {
344+ canonicalized. apply_solution ( self , substs. 0 ) ;
345+ self . obligations . push ( obligation) ;
346+ }
347+ Some ( _) => {
348+ // FIXME use this when trying to resolve everything at the end
349+ self . obligations . push ( obligation) ;
350+ }
351+ None => {
352+ // FIXME obligation cannot be fulfilled => diagnostic
376353 }
377354 } ;
378355 }
0 commit comments