@@ -582,14 +582,24 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
582582 ) ;
583583
584584 if borrowed_place_has_mut_interior {
585- // Locals without StorageDead follow the "enclosing scope" rule, meaning
586- // they are essentially anonymous static items themselves.
587- // Note: This is only sound if every local that has a `StorageDead` has a
588- // `StorageDead` in every control flow path leading to a `return` terminator.
589- if self . local_has_storage_dead ( place. local ) {
590- self . check_op ( ops:: TransientCellBorrow ) ;
591- } else {
592- self . check_op ( ops:: CellBorrow ) ;
585+ match self . const_kind ( ) {
586+ // In a const fn all borrows are transient or point to the places given via
587+ // references in the arguments. The borrow checker guarantees that.
588+ // NOTE: Once we have heap allocations during CTFE we need to figure out
589+ // how to prevent `const fn` to create long-lived allocations that point
590+ // to (interior) mutable memory.
591+ hir:: ConstContext :: ConstFn => self . check_op ( ops:: TransientCellBorrow ) ,
592+ _ => {
593+ // Locals without StorageDead follow the "enclosing scope" rule, meaning
594+ // they are essentially anonymous static items themselves.
595+ // Note: This is only sound if every local that has a `StorageDead` has a
596+ // `StorageDead` in every control flow path leading to a `return` terminator.
597+ if self . local_has_storage_dead ( place. local ) {
598+ self . check_op ( ops:: TransientCellBorrow ) ;
599+ } else {
600+ self . check_op ( ops:: CellBorrow ) ;
601+ }
602+ }
593603 }
594604 }
595605 }
0 commit comments