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