@@ -135,9 +135,9 @@ fn check_rvalue<'tcx>(
135
135
match rvalue {
136
136
Rvalue :: ThreadLocalRef ( _) => Err ( ( span, "cannot access thread local storage in const fn" . into ( ) ) ) ,
137
137
Rvalue :: Len ( place) | Rvalue :: Discriminant ( place) | Rvalue :: Ref ( _, _, place) | Rvalue :: AddressOf ( _, place) => {
138
- check_place ( tcx, * place, span, body, false )
138
+ check_place ( tcx, * place, span, body)
139
139
} ,
140
- Rvalue :: CopyForDeref ( place) => check_place ( tcx, * place, span, body, false ) ,
140
+ Rvalue :: CopyForDeref ( place) => check_place ( tcx, * place, span, body) ,
141
141
Rvalue :: Repeat ( operand, _)
142
142
| Rvalue :: Use ( operand)
143
143
| Rvalue :: Cast (
@@ -230,14 +230,14 @@ fn check_statement<'tcx>(
230
230
let span = statement. source_info . span ;
231
231
match & statement. kind {
232
232
StatementKind :: Assign ( box ( place, rval) ) => {
233
- check_place ( tcx, * place, span, body, false ) ?;
233
+ check_place ( tcx, * place, span, body) ?;
234
234
check_rvalue ( tcx, body, def_id, rval, span)
235
235
} ,
236
236
237
- StatementKind :: FakeRead ( box ( _, place) ) => check_place ( tcx, * place, span, body, false ) ,
237
+ StatementKind :: FakeRead ( box ( _, place) ) => check_place ( tcx, * place, span, body) ,
238
238
// just an assignment
239
239
StatementKind :: SetDiscriminant { place, .. } | StatementKind :: Deinit ( place) => {
240
- check_place ( tcx, * * place, span, body, false )
240
+ check_place ( tcx, * * place, span, body)
241
241
} ,
242
242
243
243
StatementKind :: Intrinsic ( box NonDivergingIntrinsic :: Assume ( op) ) => check_operand ( tcx, op, span, body) ,
@@ -263,29 +263,29 @@ fn check_statement<'tcx>(
263
263
264
264
fn check_operand < ' tcx > ( tcx : TyCtxt < ' tcx > , operand : & Operand < ' tcx > , span : Span , body : & Body < ' tcx > ) -> McfResult {
265
265
match operand {
266
- Operand :: Move ( place) => check_place ( tcx, * place, span, body, true ) ,
267
- Operand :: Copy ( place) => check_place ( tcx, * place, span, body, false ) ,
266
+ Operand :: Move ( place) => {
267
+ if !place. projection . as_ref ( ) . is_empty ( )
268
+ && !is_ty_const_destruct ( tcx, place. ty ( & body. local_decls , tcx) . ty , body)
269
+ {
270
+ return Err ( (
271
+ span,
272
+ "cannot drop locals with a non constant destructor in const fn" . into ( ) ,
273
+ ) ) ;
274
+ }
275
+
276
+ check_place ( tcx, * place, span, body)
277
+ } ,
278
+ Operand :: Copy ( place) => check_place ( tcx, * place, span, body) ,
268
279
Operand :: Constant ( c) => match c. check_static_ptr ( tcx) {
269
280
Some ( _) => Err ( ( span, "cannot access `static` items in const fn" . into ( ) ) ) ,
270
281
None => Ok ( ( ) ) ,
271
282
} ,
272
283
}
273
284
}
274
285
275
- fn check_place < ' tcx > ( tcx : TyCtxt < ' tcx > , place : Place < ' tcx > , span : Span , body : & Body < ' tcx > , in_move : bool ) -> McfResult {
286
+ fn check_place < ' tcx > ( tcx : TyCtxt < ' tcx > , place : Place < ' tcx > , span : Span , body : & Body < ' tcx > ) -> McfResult {
276
287
let mut cursor = place. projection . as_ref ( ) ;
277
288
278
- if let [ proj_base] = cursor
279
- && let ProjectionElem :: Field ( _, ty) = proj_base
280
- && !is_ty_const_destruct ( tcx, * ty, body)
281
- && in_move
282
- {
283
- return Err ( (
284
- span,
285
- "cannot drop locals with a non constant destructor in const fn" . into ( ) ,
286
- ) ) ;
287
- }
288
-
289
289
while let [ ref proj_base @ .., elem] = * cursor {
290
290
cursor = proj_base;
291
291
match elem {
0 commit comments