]> git.lizzy.rs Git - rust.git/blob - tests/ui/union/union-with-drop-fields.rs
Rollup merge of #107780 - compiler-errors:instantiate-binder, r=lcnr
[rust.git] / tests / ui / union / union-with-drop-fields.rs
1 // revisions: mirunsafeck thirunsafeck
2 // [thirunsafeck]compile-flags: -Z thir-unsafeck
3
4 #![allow(dead_code)]
5
6 union U {
7     a: u8, // OK
8 }
9
10 union W {
11     a: String, //~ ERROR unions cannot contain fields that may need dropping
12     b: String, // OK, only one field is reported
13 }
14
15 struct S(String);
16
17 // `S` doesn't implement `Drop` trait, but still has non-trivial destructor
18 union Y {
19     a: S, //~ ERROR unions cannot contain fields that may need dropping
20 }
21
22 // We don't know if `T` is trivially-destructable or not until trans
23 union J<T> {
24     a: T, //~ ERROR unions cannot contain fields that may need dropping
25 }
26
27 union H<T: Copy> {
28     a: T, // OK, `T` is `Copy`, no destructor
29 }
30
31 fn main() {}