@@ -40,21 +40,18 @@ pub trait Qualif {
4040 Self :: in_any_value_of_ty ( cx, ty) . unwrap_or ( true )
4141 }
4242
43- fn in_local ( cx : & ConstCx < ' _ , ' _ > , local : Local ) -> bool {
44- cx. per_local . 0 [ Self :: IDX ] . contains ( local)
45- }
46-
4743 fn in_static ( _cx : & ConstCx < ' _ , ' tcx > , _static : & Static < ' tcx > ) -> bool {
4844 // FIXME(eddyb) should we do anything here for value properties?
4945 false
5046 }
5147
5248 fn in_projection_structurally (
5349 cx : & ConstCx < ' _ , ' tcx > ,
50+ per_local : & BitSet < Local > ,
5451 place : PlaceRef < ' _ , ' tcx > ,
5552 ) -> bool {
5653 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 {
5855 base : place. base ,
5956 projection : proj_base,
6057 } ) ;
@@ -71,7 +68,7 @@ pub trait Qualif {
7168 ProjectionElem :: ConstantIndex { .. } |
7269 ProjectionElem :: Downcast ( ..) => qualif,
7370
74- ProjectionElem :: Index ( local) => qualif || Self :: in_local ( cx , * local) ,
71+ ProjectionElem :: Index ( local) => qualif || per_local . contains ( * local) ,
7572 }
7673 } else {
7774 bug ! ( "This should be called if projection is not empty" ) ;
@@ -80,17 +77,22 @@ pub trait Qualif {
8077
8178 fn in_projection (
8279 cx : & ConstCx < ' _ , ' tcx > ,
80+ per_local : & BitSet < Local > ,
8381 place : PlaceRef < ' _ , ' tcx > ,
8482 ) -> bool {
85- Self :: in_projection_structurally ( cx, place)
83+ Self :: in_projection_structurally ( cx, per_local , place)
8684 }
8785
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 {
8991 match place {
9092 PlaceRef {
9193 base : PlaceBase :: Local ( local) ,
9294 projection : [ ] ,
93- } => Self :: in_local ( cx , * local) ,
95+ } => per_local . contains ( * local) ,
9496 PlaceRef {
9597 base : PlaceBase :: Static ( box Static {
9698 kind : StaticKind :: Promoted ( ..) ,
@@ -107,14 +109,18 @@ pub trait Qualif {
107109 PlaceRef {
108110 base : _,
109111 projection : [ .., _] ,
110- } => Self :: in_projection ( cx, place) ,
112+ } => Self :: in_projection ( cx, per_local , place) ,
111113 }
112114 }
113115
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 {
115121 match * operand {
116122 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 ( ) ) ,
118124
119125 Operand :: Constant ( ref constant) => {
120126 if let ConstValue :: Unevaluated ( def_id, _) = constant. literal . val {
@@ -138,21 +144,25 @@ pub trait Qualif {
138144 }
139145 }
140146
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 {
142152 match * rvalue {
143153 Rvalue :: NullaryOp ( ..) => false ,
144154
145155 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 ( ) ) ,
147157
148158 Rvalue :: Use ( ref operand) |
149159 Rvalue :: Repeat ( ref operand, _) |
150160 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) ,
152162
153163 Rvalue :: BinaryOp ( _, ref lhs, ref rhs) |
154164 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)
156166 }
157167
158168 Rvalue :: Ref ( _, _, ref place) => {
@@ -161,29 +171,30 @@ pub trait Qualif {
161171 if ProjectionElem :: Deref == * elem {
162172 let base_ty = Place :: ty_from ( & place. base , proj_base, cx. body , cx. tcx ) . ty ;
163173 if let ty:: Ref ( ..) = base_ty. sty {
164- return Self :: in_place ( cx, PlaceRef {
174+ return Self :: in_place ( cx, per_local , PlaceRef {
165175 base : & place. base ,
166176 projection : proj_base,
167177 } ) ;
168178 }
169179 }
170180 }
171181
172- Self :: in_place ( cx, place. as_ref ( ) )
182+ Self :: in_place ( cx, per_local , place. as_ref ( ) )
173183 }
174184
175185 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) )
177187 }
178188 }
179189 }
180190
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)
183193 }
184194
185195 fn in_call (
186196 cx : & ConstCx < ' _ , ' tcx > ,
197+ _per_local : & BitSet < Local > ,
187198 _callee : & Operand < ' tcx > ,
188199 _args : & [ Operand < ' tcx > ] ,
189200 return_ty : Ty < ' tcx > ,
@@ -207,7 +218,7 @@ impl Qualif for HasMutInterior {
207218 Some ( !ty. is_freeze ( cx. tcx , cx. param_env , DUMMY_SP ) )
208219 }
209220
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 {
211222 match * rvalue {
212223 // Returning `true` for `Rvalue::Ref` indicates the borrow isn't
213224 // allowed in constants (and the `Checker` will error), and/or it
@@ -247,7 +258,7 @@ impl Qualif for HasMutInterior {
247258 _ => { }
248259 }
249260
250- Self :: in_rvalue_structurally ( cx, rvalue)
261+ Self :: in_rvalue_structurally ( cx, per_local , rvalue)
251262 }
252263}
253264
@@ -265,7 +276,7 @@ impl Qualif for NeedsDrop {
265276 Some ( ty. needs_drop ( cx. tcx , cx. param_env ) )
266277 }
267278
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 {
269280 if let Rvalue :: Aggregate ( ref kind, _) = * rvalue {
270281 if let AggregateKind :: Adt ( def, ..) = * * kind {
271282 if def. has_dtor ( cx. tcx ) {
@@ -274,6 +285,6 @@ impl Qualif for NeedsDrop {
274285 }
275286 }
276287
277- Self :: in_rvalue_structurally ( cx, rvalue)
288+ Self :: in_rvalue_structurally ( cx, per_local , rvalue)
278289 }
279290}
0 commit comments