1
1
use rustc_infer:: infer:: nll_relate:: { NormalizationStrategy , TypeRelating , TypeRelatingDelegate } ;
2
- use rustc_infer:: infer:: { InferCtxt , NllRegionVariableOrigin } ;
2
+ use rustc_infer:: infer:: NllRegionVariableOrigin ;
3
3
use rustc_middle:: mir:: ConstraintCategory ;
4
4
use rustc_middle:: ty:: relate:: TypeRelation ;
5
5
use rustc_middle:: ty:: { self , Const , Ty } ;
6
6
use rustc_trait_selection:: traits:: query:: Fallible ;
7
7
8
8
use crate :: constraints:: OutlivesConstraint ;
9
9
use crate :: diagnostics:: UniverseInfo ;
10
- use crate :: type_check:: { BorrowCheckContext , Locations } ;
10
+ use crate :: type_check:: { Locations , TypeChecker } ;
11
11
12
12
/// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`:
13
13
///
@@ -17,38 +17,26 @@ use crate::type_check::{BorrowCheckContext, Locations};
17
17
///
18
18
/// N.B., the type `a` is permitted to have unresolved inference
19
19
/// variables, but not the type `b`.
20
- #[ instrument( skip( infcx , param_env , borrowck_context ) , level = "debug" ) ]
20
+ #[ instrument( skip( type_checker ) , level = "debug" ) ]
21
21
pub ( super ) fn relate_types < ' tcx > (
22
- infcx : & InferCtxt < ' _ , ' tcx > ,
23
- param_env : ty:: ParamEnv < ' tcx > ,
22
+ type_checker : & mut TypeChecker < ' _ , ' tcx > ,
24
23
a : Ty < ' tcx > ,
25
24
v : ty:: Variance ,
26
25
b : Ty < ' tcx > ,
27
26
locations : Locations ,
28
27
category : ConstraintCategory ,
29
- borrowck_context : & mut BorrowCheckContext < ' _ , ' tcx > ,
30
28
) -> Fallible < ( ) > {
31
29
TypeRelating :: new (
32
- infcx,
33
- NllTypeRelatingDelegate :: new (
34
- infcx,
35
- borrowck_context,
36
- param_env,
37
- locations,
38
- category,
39
- UniverseInfo :: relate ( a, b) ,
40
- ) ,
30
+ type_checker. infcx ,
31
+ NllTypeRelatingDelegate :: new ( type_checker, locations, category, UniverseInfo :: relate ( a, b) ) ,
41
32
v,
42
33
)
43
34
. relate ( a, b) ?;
44
35
Ok ( ( ) )
45
36
}
46
37
47
38
struct NllTypeRelatingDelegate < ' me , ' bccx , ' tcx > {
48
- infcx : & ' me InferCtxt < ' me , ' tcx > ,
49
- borrowck_context : & ' me mut BorrowCheckContext < ' bccx , ' tcx > ,
50
-
51
- param_env : ty:: ParamEnv < ' tcx > ,
39
+ type_checker : & ' me mut TypeChecker < ' bccx , ' tcx > ,
52
40
53
41
/// Where (and why) is this relation taking place?
54
42
locations : Locations ,
@@ -63,25 +51,24 @@ struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
63
51
64
52
impl NllTypeRelatingDelegate < ' me , ' bccx , ' tcx > {
65
53
fn new (
66
- infcx : & ' me InferCtxt < ' me , ' tcx > ,
67
- borrowck_context : & ' me mut BorrowCheckContext < ' bccx , ' tcx > ,
68
- param_env : ty:: ParamEnv < ' tcx > ,
54
+ type_checker : & ' me mut TypeChecker < ' bccx , ' tcx > ,
69
55
locations : Locations ,
70
56
category : ConstraintCategory ,
71
57
universe_info : UniverseInfo < ' tcx > ,
72
58
) -> Self {
73
- Self { infcx , borrowck_context , param_env , locations, category, universe_info }
59
+ Self { type_checker , locations, category, universe_info }
74
60
}
75
61
}
76
62
77
63
impl TypeRelatingDelegate < ' tcx > for NllTypeRelatingDelegate < ' _ , ' _ , ' tcx > {
78
64
fn param_env ( & self ) -> ty:: ParamEnv < ' tcx > {
79
- self . param_env
65
+ self . type_checker . param_env
80
66
}
81
67
82
68
fn create_next_universe ( & mut self ) -> ty:: UniverseIndex {
83
- let universe = self . infcx . create_next_universe ( ) ;
84
- self . borrowck_context
69
+ let universe = self . type_checker . infcx . create_next_universe ( ) ;
70
+ self . type_checker
71
+ . borrowck_context
85
72
. constraints
86
73
. universe_causes
87
74
. insert ( universe, self . universe_info . clone ( ) ) ;
@@ -90,15 +77,18 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
90
77
91
78
fn next_existential_region_var ( & mut self , from_forall : bool ) -> ty:: Region < ' tcx > {
92
79
let origin = NllRegionVariableOrigin :: Existential { from_forall } ;
93
- self . infcx . next_nll_region_var ( origin)
80
+ self . type_checker . infcx . next_nll_region_var ( origin)
94
81
}
95
82
96
83
fn next_placeholder_region ( & mut self , placeholder : ty:: PlaceholderRegion ) -> ty:: Region < ' tcx > {
97
- self . borrowck_context . constraints . placeholder_region ( self . infcx , placeholder)
84
+ self . type_checker
85
+ . borrowck_context
86
+ . constraints
87
+ . placeholder_region ( self . type_checker . infcx , placeholder)
98
88
}
99
89
100
90
fn generalize_existential ( & mut self , universe : ty:: UniverseIndex ) -> ty:: Region < ' tcx > {
101
- self . infcx . next_nll_region_var_in_universe (
91
+ self . type_checker . infcx . next_nll_region_var_in_universe (
102
92
NllRegionVariableOrigin :: Existential { from_forall : false } ,
103
93
universe,
104
94
)
@@ -110,15 +100,17 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
110
100
sub : ty:: Region < ' tcx > ,
111
101
info : ty:: VarianceDiagInfo < ' tcx > ,
112
102
) {
113
- let sub = self . borrowck_context . universal_regions . to_region_vid ( sub) ;
114
- let sup = self . borrowck_context . universal_regions . to_region_vid ( sup) ;
115
- self . borrowck_context . constraints . outlives_constraints . push ( OutlivesConstraint {
116
- sup,
117
- sub,
118
- locations : self . locations ,
119
- category : self . category ,
120
- variance_info : info,
121
- } ) ;
103
+ let sub = self . type_checker . borrowck_context . universal_regions . to_region_vid ( sub) ;
104
+ let sup = self . type_checker . borrowck_context . universal_regions . to_region_vid ( sup) ;
105
+ self . type_checker . borrowck_context . constraints . outlives_constraints . push (
106
+ OutlivesConstraint {
107
+ sup,
108
+ sub,
109
+ locations : self . locations ,
110
+ category : self . category ,
111
+ variance_info : info,
112
+ } ,
113
+ ) ;
122
114
}
123
115
124
116
// We don't have to worry about the equality of consts during borrow checking
0 commit comments