5
5
use rustc_hir as hir;
6
6
use rustc_infer:: infer:: canonical:: { self , Canonical } ;
7
7
use rustc_infer:: infer:: outlives:: components:: { push_outlives_components, Component } ;
8
- use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
8
+ use rustc_infer:: infer:: TyCtxtInferExt ;
9
9
use rustc_infer:: traits:: query:: OutlivesBound ;
10
- use rustc_infer:: traits:: TraitEngineExt as _;
11
10
use rustc_middle:: ty:: query:: Providers ;
12
11
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitable } ;
13
12
use rustc_span:: source_map:: DUMMY_SP ;
14
13
use rustc_trait_selection:: infer:: InferCtxtBuilderExt ;
15
14
use rustc_trait_selection:: traits:: query:: { CanonicalTyGoal , Fallible , NoSolution } ;
16
15
use rustc_trait_selection:: traits:: wf;
17
- use rustc_trait_selection:: traits:: { TraitEngine , TraitEngineExt } ;
16
+ use rustc_trait_selection:: traits:: ObligationCtxt ;
18
17
use smallvec:: { smallvec, SmallVec } ;
19
18
20
19
pub ( crate ) fn provide ( p : & mut Providers ) {
@@ -30,16 +29,16 @@ fn implied_outlives_bounds<'tcx>(
30
29
> {
31
30
tcx. infer_ctxt ( ) . enter_canonical_trait_query ( & goal, |ocx, key| {
32
31
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)
34
33
} )
35
34
}
36
35
37
36
fn compute_implied_outlives_bounds < ' tcx > (
38
- infcx : & InferCtxt < ' tcx > ,
37
+ ocx : & ObligationCtxt < ' _ , ' tcx > ,
39
38
param_env : ty:: ParamEnv < ' tcx > ,
40
39
ty : Ty < ' tcx > ,
41
40
) -> Fallible < Vec < OutlivesBound < ' tcx > > > {
42
- let tcx = infcx. tcx ;
41
+ let tcx = ocx . infcx . tcx ;
43
42
44
43
// Sometimes when we ask what it takes for T: WF, we get back that
45
44
// U: WF is required; in that case, we push U onto this stack and
@@ -52,8 +51,6 @@ fn compute_implied_outlives_bounds<'tcx>(
52
51
let mut outlives_bounds: Vec < ty:: OutlivesPredicate < ty:: GenericArg < ' tcx > , ty:: Region < ' tcx > > > =
53
52
vec ! [ ] ;
54
53
55
- let mut fulfill_cx = <dyn TraitEngine < ' tcx > >:: new ( tcx) ;
56
-
57
54
while let Some ( arg) = wf_args. pop ( ) {
58
55
if !checked_wf_args. insert ( arg) {
59
56
continue ;
@@ -70,15 +67,15 @@ fn compute_implied_outlives_bounds<'tcx>(
70
67
// FIXME(@lcnr): It's not really "always fine", having fewer implied
71
68
// bounds can be backward incompatible, e.g. #101951 was caused by
72
69
// 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 ( ) ;
75
73
76
74
// While these predicates should all be implied by other parts of
77
75
// the program, they are still relevant as they may constrain
78
76
// inference variables, which is necessary to add the correct
79
77
// implied bounds in some cases, mostly when dealing with projections.
80
- fulfill_cx. register_predicate_obligations (
81
- infcx,
78
+ ocx. register_obligations (
82
79
obligations. iter ( ) . filter ( |o| o. predicate . has_non_region_infer ( ) ) . cloned ( ) ,
83
80
) ;
84
81
@@ -116,9 +113,9 @@ fn compute_implied_outlives_bounds<'tcx>(
116
113
} ) ) ;
117
114
}
118
115
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 ( ) {
122
119
[ ] => ( ) ,
123
120
_ => return Err ( NoSolution ) ,
124
121
}
@@ -130,7 +127,7 @@ fn compute_implied_outlives_bounds<'tcx>(
130
127
. flat_map ( |ty:: OutlivesPredicate ( a, r_b) | match a. unpack ( ) {
131
128
ty:: GenericArgKind :: Lifetime ( r_a) => vec ! [ OutlivesBound :: RegionSubRegion ( r_b, r_a) ] ,
132
129
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) ;
134
131
let mut components = smallvec ! [ ] ;
135
132
push_outlives_components ( tcx, ty_a, & mut components) ;
136
133
implied_bounds_from_components ( r_b, components)
0 commit comments