@@ -135,9 +135,9 @@ fn check_rvalue<'tcx>(
135135 match rvalue {
136136 Rvalue :: ThreadLocalRef ( _) => Err ( ( span, "cannot access thread local storage in const fn" . into ( ) ) ) ,
137137 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)
139139 } ,
140- Rvalue :: CopyForDeref ( place) => check_place ( tcx, * place, span, body, false ) ,
140+ Rvalue :: CopyForDeref ( place) => check_place ( tcx, * place, span, body) ,
141141 Rvalue :: Repeat ( operand, _)
142142 | Rvalue :: Use ( operand)
143143 | Rvalue :: Cast (
@@ -230,14 +230,14 @@ fn check_statement<'tcx>(
230230 let span = statement. source_info . span ;
231231 match & statement. kind {
232232 StatementKind :: Assign ( box ( place, rval) ) => {
233- check_place ( tcx, * place, span, body, false ) ?;
233+ check_place ( tcx, * place, span, body) ?;
234234 check_rvalue ( tcx, body, def_id, rval, span)
235235 } ,
236236
237- StatementKind :: FakeRead ( box ( _, place) ) => check_place ( tcx, * place, span, body, false ) ,
237+ StatementKind :: FakeRead ( box ( _, place) ) => check_place ( tcx, * place, span, body) ,
238238 // just an assignment
239239 StatementKind :: SetDiscriminant { place, .. } | StatementKind :: Deinit ( place) => {
240- check_place ( tcx, * * place, span, body, false )
240+ check_place ( tcx, * * place, span, body)
241241 } ,
242242
243243 StatementKind :: Intrinsic ( box NonDivergingIntrinsic :: Assume ( op) ) => check_operand ( tcx, op, span, body) ,
@@ -263,29 +263,29 @@ fn check_statement<'tcx>(
263263
264264fn check_operand < ' tcx > ( tcx : TyCtxt < ' tcx > , operand : & Operand < ' tcx > , span : Span , body : & Body < ' tcx > ) -> McfResult {
265265 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) ,
268279 Operand :: Constant ( c) => match c. check_static_ptr ( tcx) {
269280 Some ( _) => Err ( ( span, "cannot access `static` items in const fn" . into ( ) ) ) ,
270281 None => Ok ( ( ) ) ,
271282 } ,
272283 }
273284}
274285
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 {
276287 let mut cursor = place. projection . as_ref ( ) ;
277288
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-
289289 while let [ ref proj_base @ .., elem] = * cursor {
290290 cursor = proj_base;
291291 match elem {
0 commit comments