about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-27 22:13:05 +0200
committerGitHub <noreply@github.com>2025-06-27 22:13:05 +0200
commit2d59c4e0fe7c012e59a985f7313ce1c5ec6e0e47 (patch)
tree8ca1be36b7edd8f6eebe7c14ea72a31e85b3422a /tests
parent9108907a18d9b9ac46e361cced0fbfca6252f170 (diff)
parent7de39f55dd888dd81e436ac100ac563206844c6c (diff)
downloadrust-2d59c4e0fe7c012e59a985f7313ce1c5ec6e0e47.tar.gz
rust-2d59c4e0fe7c012e59a985f7313ce1c5ec6e0e47.zip
Rollup merge of #143046 - RalfJung:zst-unsafe-cell, r=lcnr,oli-obk
const validation: properly ignore zero-sized UnsafeCell

Fixes https://github.com/rust-lang/rust/issues/142948
r? `@oli-obk`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/consts/unsafe_cell_in_const.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/ui/consts/unsafe_cell_in_const.rs b/tests/ui/consts/unsafe_cell_in_const.rs
new file mode 100644
index 00000000000..b867ae1ba9f
--- /dev/null
+++ b/tests/ui/consts/unsafe_cell_in_const.rs
@@ -0,0 +1,15 @@
+//! Ensure we do not complain about zero-sized `UnsafeCell` in a const in any form.
+//! See <https://github.com/rust-lang/rust/issues/142948>.
+
+//@ check-pass
+use std::cell::UnsafeCell;
+
+const X1: &mut UnsafeCell<[i32; 0]> = UnsafeCell::from_mut(&mut []);
+
+const X2: &mut UnsafeCell<[i32]> = UnsafeCell::from_mut(&mut []);
+
+trait Trait {}
+impl Trait for [i32; 0] {}
+const X3: &mut UnsafeCell<dyn Trait> = UnsafeCell::from_mut(&mut []);
+
+fn main() {}