diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/union/field_checks.rs | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/union/field_checks.rs')
-rw-r--r-- | tests/ui/union/field_checks.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/ui/union/field_checks.rs b/tests/ui/union/field_checks.rs new file mode 100644 index 000000000..d5d1e44ac --- /dev/null +++ b/tests/ui/union/field_checks.rs @@ -0,0 +1,65 @@ +use std::mem::ManuallyDrop; + +union U1 { // OK + a: u8, +} + +union U2<T: Copy> { // OK + a: T, +} + +union U22<T> { // OK + a: ManuallyDrop<T>, +} + +union U23<T> { // OK + a: (ManuallyDrop<T>, i32), +} + +union U24<T> { // OK + a: [ManuallyDrop<T>; 2], +} + +union U3 { + a: String, //~ ERROR unions cannot contain fields that may need dropping +} + +union U32 { // field that does not drop but is not `Copy`, either + a: std::cell::RefCell<i32>, //~ ERROR unions cannot contain fields that may need dropping +} + +union U4<T> { + a: T, //~ ERROR unions cannot contain fields that may need dropping +} + +union U5 { // Having a drop impl is OK + a: u8, +} + +impl Drop for U5 { + fn drop(&mut self) {} +} + +union U5Nested { // a nested union that drops is NOT OK + nest: U5, //~ ERROR unions cannot contain fields that may need dropping +} + +union U5Nested2 { // for now we don't special-case empty arrays + nest: [U5; 0], //~ ERROR unions cannot contain fields that may need dropping +} + +union U6 { // OK + s: &'static i32, + m: &'static mut i32, +} + +union U7<T> { // OK + f: (&'static mut i32, ManuallyDrop<T>, i32), +} + +union U8<T> { // OK + f1: [(&'static mut i32, i32); 8], + f2: [ManuallyDrop<T>; 2], +} + +fn main() {} |