@@ -40,21 +40,18 @@ pub trait Qualif {
40
40
Self :: in_any_value_of_ty ( cx, ty) . unwrap_or ( true )
41
41
}
42
42
43
- fn in_local ( cx : & ConstCx < ' _ , ' _ > , local : Local ) -> bool {
44
- cx. per_local . 0 [ Self :: IDX ] . contains ( local)
45
- }
46
-
47
43
fn in_static ( _cx : & ConstCx < ' _ , ' tcx > , _static : & Static < ' tcx > ) -> bool {
48
44
// FIXME(eddyb) should we do anything here for value properties?
49
45
false
50
46
}
51
47
52
48
fn in_projection_structurally (
53
49
cx : & ConstCx < ' _ , ' tcx > ,
50
+ per_local : & BitSet < Local > ,
54
51
place : PlaceRef < ' _ , ' tcx > ,
55
52
) -> bool {
56
53
if let [ proj_base @ .., elem] = place. projection {
57
- let base_qualif = Self :: in_place ( cx, PlaceRef {
54
+ let base_qualif = Self :: in_place ( cx, per_local , PlaceRef {
58
55
base : place. base ,
59
56
projection : proj_base,
60
57
} ) ;
@@ -71,7 +68,7 @@ pub trait Qualif {
71
68
ProjectionElem :: ConstantIndex { .. } |
72
69
ProjectionElem :: Downcast ( ..) => qualif,
73
70
74
- ProjectionElem :: Index ( local) => qualif || Self :: in_local ( cx , * local) ,
71
+ ProjectionElem :: Index ( local) => qualif || per_local . contains ( * local) ,
75
72
}
76
73
} else {
77
74
bug ! ( "This should be called if projection is not empty" ) ;
@@ -80,17 +77,22 @@ pub trait Qualif {
80
77
81
78
fn in_projection (
82
79
cx : & ConstCx < ' _ , ' tcx > ,
80
+ per_local : & BitSet < Local > ,
83
81
place : PlaceRef < ' _ , ' tcx > ,
84
82
) -> bool {
85
- Self :: in_projection_structurally ( cx, place)
83
+ Self :: in_projection_structurally ( cx, per_local , place)
86
84
}
87
85
88
- fn in_place ( cx : & ConstCx < ' _ , ' tcx > , place : PlaceRef < ' _ , ' tcx > ) -> bool {
86
+ fn in_place (
87
+ cx : & ConstCx < ' _ , ' tcx > ,
88
+ per_local : & BitSet < Local > ,
89
+ place : PlaceRef < ' _ , ' tcx > ,
90
+ ) -> bool {
89
91
match place {
90
92
PlaceRef {
91
93
base : PlaceBase :: Local ( local) ,
92
94
projection : [ ] ,
93
- } => Self :: in_local ( cx , * local) ,
95
+ } => per_local . contains ( * local) ,
94
96
PlaceRef {
95
97
base : PlaceBase :: Static ( box Static {
96
98
kind : StaticKind :: Promoted ( ..) ,
@@ -107,14 +109,18 @@ pub trait Qualif {
107
109
PlaceRef {
108
110
base : _,
109
111
projection : [ .., _] ,
110
- } => Self :: in_projection ( cx, place) ,
112
+ } => Self :: in_projection ( cx, per_local , place) ,
111
113
}
112
114
}
113
115
114
- fn in_operand ( cx : & ConstCx < ' _ , ' tcx > , operand : & Operand < ' tcx > ) -> bool {
116
+ fn in_operand (
117
+ cx : & ConstCx < ' _ , ' tcx > ,
118
+ per_local : & BitSet < Local > ,
119
+ operand : & Operand < ' tcx > ,
120
+ ) -> bool {
115
121
match * operand {
116
122
Operand :: Copy ( ref place) |
117
- Operand :: Move ( ref place) => Self :: in_place ( cx, place. as_ref ( ) ) ,
123
+ Operand :: Move ( ref place) => Self :: in_place ( cx, per_local , place. as_ref ( ) ) ,
118
124
119
125
Operand :: Constant ( ref constant) => {
120
126
if let ConstValue :: Unevaluated ( def_id, _) = constant. literal . val {
@@ -138,21 +144,25 @@ pub trait Qualif {
138
144
}
139
145
}
140
146
141
- fn in_rvalue_structurally ( cx : & ConstCx < ' _ , ' tcx > , rvalue : & Rvalue < ' tcx > ) -> bool {
147
+ fn in_rvalue_structurally (
148
+ cx : & ConstCx < ' _ , ' tcx > ,
149
+ per_local : & BitSet < Local > ,
150
+ rvalue : & Rvalue < ' tcx > ,
151
+ ) -> bool {
142
152
match * rvalue {
143
153
Rvalue :: NullaryOp ( ..) => false ,
144
154
145
155
Rvalue :: Discriminant ( ref place) |
146
- Rvalue :: Len ( ref place) => Self :: in_place ( cx, place. as_ref ( ) ) ,
156
+ Rvalue :: Len ( ref place) => Self :: in_place ( cx, per_local , place. as_ref ( ) ) ,
147
157
148
158
Rvalue :: Use ( ref operand) |
149
159
Rvalue :: Repeat ( ref operand, _) |
150
160
Rvalue :: UnaryOp ( _, ref operand) |
151
- Rvalue :: Cast ( _, ref operand, _) => Self :: in_operand ( cx, operand) ,
161
+ Rvalue :: Cast ( _, ref operand, _) => Self :: in_operand ( cx, per_local , operand) ,
152
162
153
163
Rvalue :: BinaryOp ( _, ref lhs, ref rhs) |
154
164
Rvalue :: CheckedBinaryOp ( _, ref lhs, ref rhs) => {
155
- Self :: in_operand ( cx, lhs) || Self :: in_operand ( cx, rhs)
165
+ Self :: in_operand ( cx, per_local , lhs) || Self :: in_operand ( cx, per_local , rhs)
156
166
}
157
167
158
168
Rvalue :: Ref ( _, _, ref place) => {
@@ -161,29 +171,30 @@ pub trait Qualif {
161
171
if ProjectionElem :: Deref == * elem {
162
172
let base_ty = Place :: ty_from ( & place. base , proj_base, cx. body , cx. tcx ) . ty ;
163
173
if let ty:: Ref ( ..) = base_ty. sty {
164
- return Self :: in_place ( cx, PlaceRef {
174
+ return Self :: in_place ( cx, per_local , PlaceRef {
165
175
base : & place. base ,
166
176
projection : proj_base,
167
177
} ) ;
168
178
}
169
179
}
170
180
}
171
181
172
- Self :: in_place ( cx, place. as_ref ( ) )
182
+ Self :: in_place ( cx, per_local , place. as_ref ( ) )
173
183
}
174
184
175
185
Rvalue :: Aggregate ( _, ref operands) => {
176
- operands. iter ( ) . any ( |o| Self :: in_operand ( cx, o) )
186
+ operands. iter ( ) . any ( |o| Self :: in_operand ( cx, per_local , o) )
177
187
}
178
188
}
179
189
}
180
190
181
- fn in_rvalue ( cx : & ConstCx < ' _ , ' tcx > , rvalue : & Rvalue < ' tcx > ) -> bool {
182
- Self :: in_rvalue_structurally ( cx, rvalue)
191
+ fn in_rvalue ( cx : & ConstCx < ' _ , ' tcx > , per_local : & BitSet < Local > , rvalue : & Rvalue < ' tcx > ) -> bool {
192
+ Self :: in_rvalue_structurally ( cx, per_local , rvalue)
183
193
}
184
194
185
195
fn in_call (
186
196
cx : & ConstCx < ' _ , ' tcx > ,
197
+ _per_local : & BitSet < Local > ,
187
198
_callee : & Operand < ' tcx > ,
188
199
_args : & [ Operand < ' tcx > ] ,
189
200
return_ty : Ty < ' tcx > ,
@@ -207,7 +218,7 @@ impl Qualif for HasMutInterior {
207
218
Some ( !ty. is_freeze ( cx. tcx , cx. param_env , DUMMY_SP ) )
208
219
}
209
220
210
- fn in_rvalue ( cx : & ConstCx < ' _ , ' tcx > , rvalue : & Rvalue < ' tcx > ) -> bool {
221
+ fn in_rvalue ( cx : & ConstCx < ' _ , ' tcx > , per_local : & BitSet < Local > , rvalue : & Rvalue < ' tcx > ) -> bool {
211
222
match * rvalue {
212
223
// Returning `true` for `Rvalue::Ref` indicates the borrow isn't
213
224
// allowed in constants (and the `Checker` will error), and/or it
@@ -247,7 +258,7 @@ impl Qualif for HasMutInterior {
247
258
_ => { }
248
259
}
249
260
250
- Self :: in_rvalue_structurally ( cx, rvalue)
261
+ Self :: in_rvalue_structurally ( cx, per_local , rvalue)
251
262
}
252
263
}
253
264
@@ -265,7 +276,7 @@ impl Qualif for NeedsDrop {
265
276
Some ( ty. needs_drop ( cx. tcx , cx. param_env ) )
266
277
}
267
278
268
- fn in_rvalue ( cx : & ConstCx < ' _ , ' tcx > , rvalue : & Rvalue < ' tcx > ) -> bool {
279
+ fn in_rvalue ( cx : & ConstCx < ' _ , ' tcx > , per_local : & BitSet < Local > , rvalue : & Rvalue < ' tcx > ) -> bool {
269
280
if let Rvalue :: Aggregate ( ref kind, _) = * rvalue {
270
281
if let AggregateKind :: Adt ( def, ..) = * * kind {
271
282
if def. has_dtor ( cx. tcx ) {
@@ -274,6 +285,6 @@ impl Qualif for NeedsDrop {
274
285
}
275
286
}
276
287
277
- Self :: in_rvalue_structurally ( cx, rvalue)
288
+ Self :: in_rvalue_structurally ( cx, per_local , rvalue)
278
289
}
279
290
}
0 commit comments