diff options
| -rw-r--r-- | compiler/rustc_mir/src/transform/check_consts/ops.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/consts/std/cell.rs | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs index 1ee6615f6f0..5112c572d0f 100644 --- a/compiler/rustc_mir/src/transform/check_consts/ops.rs +++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs @@ -227,6 +227,13 @@ impl NonConstOp for CellBorrowBehindRef { #[derive(Debug)] pub struct CellBorrow; impl NonConstOp for CellBorrow { + fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status { + match ccx.const_kind() { + // The borrow checker does a much better job at handling these than we do + hir::ConstContext::ConstFn => Status::Allowed, + _ => Status::Forbidden, + } + } fn importance(&self) -> DiagnosticImportance { // The problematic cases will already emit a `CellBorrowBehindRef` DiagnosticImportance::Secondary diff --git a/src/test/ui/consts/std/cell.rs b/src/test/ui/consts/std/cell.rs index ee4df6f43fa..de75d868c7f 100644 --- a/src/test/ui/consts/std/cell.rs +++ b/src/test/ui/consts/std/cell.rs @@ -36,4 +36,6 @@ unsafe impl<T> Sync for Wrap<T> {} static BAR_PTR: Wrap<*mut u32> = Wrap(BAR.0.get()); +const fn fst_ref<T, U>(x: &(T, U)) -> &T { &x.0 } + fn main() {} |
