55use rustc_hir as hir;
66use rustc_infer:: infer:: canonical:: { self , Canonical } ;
77use rustc_infer:: infer:: outlives:: components:: { push_outlives_components, Component } ;
8- use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
8+ use rustc_infer:: infer:: TyCtxtInferExt ;
99use rustc_infer:: traits:: query:: OutlivesBound ;
10- use rustc_infer:: traits:: TraitEngineExt as _;
1110use rustc_middle:: ty:: query:: Providers ;
1211use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitable } ;
1312use rustc_span:: source_map:: DUMMY_SP ;
1413use rustc_trait_selection:: infer:: InferCtxtBuilderExt ;
1514use rustc_trait_selection:: traits:: query:: { CanonicalTyGoal , Fallible , NoSolution } ;
1615use rustc_trait_selection:: traits:: wf;
17- use rustc_trait_selection:: traits:: { TraitEngine , TraitEngineExt } ;
16+ use rustc_trait_selection:: traits:: ObligationCtxt ;
1817use smallvec:: { smallvec, SmallVec } ;
1918
2019pub ( crate ) fn provide ( p : & mut Providers ) {
@@ -30,16 +29,16 @@ fn implied_outlives_bounds<'tcx>(
3029> {
3130 tcx. infer_ctxt ( ) . enter_canonical_trait_query ( & goal, |ocx, key| {
3231 let ( param_env, ty) = key. into_parts ( ) ;
33- compute_implied_outlives_bounds ( & ocx. infcx , param_env, ty)
32+ compute_implied_outlives_bounds ( ocx, param_env, ty)
3433 } )
3534}
3635
3736fn compute_implied_outlives_bounds < ' tcx > (
38- infcx : & InferCtxt < ' tcx > ,
37+ ocx : & ObligationCtxt < ' _ , ' tcx > ,
3938 param_env : ty:: ParamEnv < ' tcx > ,
4039 ty : Ty < ' tcx > ,
4140) -> Fallible < Vec < OutlivesBound < ' tcx > > > {
42- let tcx = infcx. tcx ;
41+ let tcx = ocx . infcx . tcx ;
4342
4443 // Sometimes when we ask what it takes for T: WF, we get back that
4544 // U: WF is required; in that case, we push U onto this stack and
@@ -52,8 +51,6 @@ fn compute_implied_outlives_bounds<'tcx>(
5251 let mut outlives_bounds: Vec < ty:: OutlivesPredicate < ty:: GenericArg < ' tcx > , ty:: Region < ' tcx > > > =
5352 vec ! [ ] ;
5453
55- let mut fulfill_cx = <dyn TraitEngine < ' tcx > >:: new ( tcx) ;
56-
5754 while let Some ( arg) = wf_args. pop ( ) {
5855 if !checked_wf_args. insert ( arg) {
5956 continue ;
@@ -70,15 +67,15 @@ fn compute_implied_outlives_bounds<'tcx>(
7067 // FIXME(@lcnr): It's not really "always fine", having fewer implied
7168 // bounds can be backward incompatible, e.g. #101951 was caused by
7269 // us not dealing with inference vars in `TypeOutlives` predicates.
73- let obligations = wf:: obligations ( infcx, param_env, hir:: CRATE_HIR_ID , 0 , arg, DUMMY_SP )
74- . unwrap_or_default ( ) ;
70+ let obligations =
71+ wf:: obligations ( ocx. infcx , param_env, hir:: CRATE_HIR_ID , 0 , arg, DUMMY_SP )
72+ . unwrap_or_default ( ) ;
7573
7674 // While these predicates should all be implied by other parts of
7775 // the program, they are still relevant as they may constrain
7876 // inference variables, which is necessary to add the correct
7977 // implied bounds in some cases, mostly when dealing with projections.
80- fulfill_cx. register_predicate_obligations (
81- infcx,
78+ ocx. register_obligations (
8279 obligations. iter ( ) . filter ( |o| o. predicate . has_non_region_infer ( ) ) . cloned ( ) ,
8380 ) ;
8481
@@ -116,9 +113,9 @@ fn compute_implied_outlives_bounds<'tcx>(
116113 } ) ) ;
117114 }
118115
119- // Ensure that those obligations that we had to solve
120- // get solved *here* .
121- match fulfill_cx . select_all_or_error ( infcx ) . as_slice ( ) {
116+ // This call to `select_all_or_error` is necessary to constrain inference variables, which we
117+ // use further down when computing the implied bounds .
118+ match ocx . select_all_or_error ( ) . as_slice ( ) {
122119 [ ] => ( ) ,
123120 _ => return Err ( NoSolution ) ,
124121 }
@@ -130,7 +127,7 @@ fn compute_implied_outlives_bounds<'tcx>(
130127 . flat_map ( |ty:: OutlivesPredicate ( a, r_b) | match a. unpack ( ) {
131128 ty:: GenericArgKind :: Lifetime ( r_a) => vec ! [ OutlivesBound :: RegionSubRegion ( r_b, r_a) ] ,
132129 ty:: GenericArgKind :: Type ( ty_a) => {
133- let ty_a = infcx. resolve_vars_if_possible ( ty_a) ;
130+ let ty_a = ocx . infcx . resolve_vars_if_possible ( ty_a) ;
134131 let mut components = smallvec ! [ ] ;
135132 push_outlives_components ( tcx, ty_a, & mut components) ;
136133 implied_bounds_from_components ( r_b, components)
0 commit comments