diff options
| author | oli <github35764891676564198441@oli-obk.de> | 2020-12-28 01:09:55 +0000 |
|---|---|---|
| committer | oli <github35764891676564198441@oli-obk.de> | 2021-01-01 16:59:12 +0000 |
| commit | 354e510f7d9e9f19b5f3ff55da83658a260bca4f (patch) | |
| tree | a3e3b98ded383ba26bae6828633825175f3c605d | |
| parent | 3a44a20ed1c3ee448c3d588e9b132ddc6cd62ab9 (diff) | |
| download | rust-354e510f7d9e9f19b5f3ff55da83658a260bca4f.tar.gz rust-354e510f7d9e9f19b5f3ff55da83658a260bca4f.zip | |
Fix cell checks in const fn
| -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() {} |
