diff --git a/tests/ui/union/field_checks.rs b/tests/ui/union/field_checks.rs index bb4eccb4cf896..6d5ddd52dfa56 100644 --- a/tests/ui/union/field_checks.rs +++ b/tests/ui/union/field_checks.rs @@ -1,3 +1,9 @@ +//@ reference: items.union.field-restrictions +//@ reference: items.union.field-copy +//@ reference: items.union.field-references +//@ reference: items.union.field-manually-drop +//@ reference: items.union.field-tuple +//@ reference: type.union.constraint use std::mem::ManuallyDrop; union U1 { // OK diff --git a/tests/ui/union/field_checks.stderr b/tests/ui/union/field_checks.stderr index 32407a749709c..8c111cd940133 100644 --- a/tests/ui/union/field_checks.stderr +++ b/tests/ui/union/field_checks.stderr @@ -1,5 +1,5 @@ error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/field_checks.rs:24:5 + --> $DIR/field_checks.rs:30:5 | LL | a: String, | ^^^^^^^^^ @@ -11,7 +11,7 @@ LL | a: std::mem::ManuallyDrop, | +++++++++++++++++++++++ + error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/field_checks.rs:28:5 + --> $DIR/field_checks.rs:34:5 | LL | a: std::cell::RefCell, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | a: std::mem::ManuallyDrop>, | +++++++++++++++++++++++ + error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/field_checks.rs:32:5 + --> $DIR/field_checks.rs:38:5 | LL | a: T, | ^^^^ @@ -35,7 +35,7 @@ LL | a: std::mem::ManuallyDrop, | +++++++++++++++++++++++ + error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/field_checks.rs:44:5 + --> $DIR/field_checks.rs:50:5 | LL | nest: U5, | ^^^^^^^^ @@ -47,7 +47,7 @@ LL | nest: std::mem::ManuallyDrop, | +++++++++++++++++++++++ + error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/field_checks.rs:48:5 + --> $DIR/field_checks.rs:54:5 | LL | nest: [U5; 0], | ^^^^^^^^^^^^^ diff --git a/tests/ui/union/union-backcomp.rs b/tests/ui/union/union-backcomp.rs index a71813968e841..46b5eb48f0c4a 100644 --- a/tests/ui/union/union-backcomp.rs +++ b/tests/ui/union/union-backcomp.rs @@ -1,4 +1,5 @@ //@ run-pass +//@ reference: lex.keywords.weak.union #![allow(path_statements)] #![allow(dead_code)] diff --git a/tests/ui/union/union-copy.rs b/tests/ui/union/union-copy.rs index 7ad0a11c6ac6e..40b43b8f3466e 100644 --- a/tests/ui/union/union-copy.rs +++ b/tests/ui/union/union-copy.rs @@ -1,3 +1,4 @@ +//@ reference: lang-types.copy.constraint #[derive(Clone)] union U { a: u8 diff --git a/tests/ui/union/union-copy.stderr b/tests/ui/union/union-copy.stderr index bd63908b49a2c..60cb49147b659 100644 --- a/tests/ui/union/union-copy.stderr +++ b/tests/ui/union/union-copy.stderr @@ -1,5 +1,5 @@ error[E0204]: the trait `Copy` cannot be implemented for this type - --> $DIR/union-copy.rs:12:15 + --> $DIR/union-copy.rs:13:15 | LL | a: std::mem::ManuallyDrop | --------------------------------- this field does not implement `Copy` @@ -8,7 +8,7 @@ LL | impl Copy for W {} | ^ | note: the `Copy` impl for `ManuallyDrop` requires that `String: Copy` - --> $DIR/union-copy.rs:8:8 + --> $DIR/union-copy.rs:9:8 | LL | a: std::mem::ManuallyDrop | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/union/union-drop.rs b/tests/ui/union/union-drop.rs index 6f6d5c1416534..a29de4f69a9bf 100644 --- a/tests/ui/union/union-drop.rs +++ b/tests/ui/union/union-drop.rs @@ -1,4 +1,5 @@ //@ run-pass +//@ reference: items.union.drop #![allow(dead_code)] #![allow(unused_variables)] diff --git a/tests/ui/union/union-empty.rs b/tests/ui/union/union-empty.rs index 79b7e68ee6beb..60b6668b6e245 100644 --- a/tests/ui/union/union-empty.rs +++ b/tests/ui/union/union-empty.rs @@ -1,3 +1,4 @@ +//@ reference: items.union.fieldless union U {} //~ ERROR unions cannot have zero fields fn main() {} diff --git a/tests/ui/union/union-empty.stderr b/tests/ui/union/union-empty.stderr index 03a939769c78b..aeec4eca5a996 100644 --- a/tests/ui/union/union-empty.stderr +++ b/tests/ui/union/union-empty.stderr @@ -1,5 +1,5 @@ error: unions cannot have zero fields - --> $DIR/union-empty.rs:1:1 + --> $DIR/union-empty.rs:2:1 | LL | union U {} | ^^^^^^^^^^ diff --git a/tests/ui/union/union-fields-2.rs b/tests/ui/union/union-fields-2.rs index 71b204fcdc5b8..981fbff63ebda 100644 --- a/tests/ui/union/union-fields-2.rs +++ b/tests/ui/union/union-fields-2.rs @@ -1,3 +1,4 @@ +//@ reference: items.union.init.intro union U { a: u8, b: u16, diff --git a/tests/ui/union/union-fields-2.stderr b/tests/ui/union/union-fields-2.stderr index 142186885caa8..4a39f5ec36c50 100644 --- a/tests/ui/union/union-fields-2.stderr +++ b/tests/ui/union/union-fields-2.stderr @@ -1,17 +1,17 @@ error[E0784]: union expressions should have exactly one field - --> $DIR/union-fields-2.rs:7:13 + --> $DIR/union-fields-2.rs:8:13 | LL | let u = U {}; | ^ error[E0784]: union expressions should have exactly one field - --> $DIR/union-fields-2.rs:9:13 + --> $DIR/union-fields-2.rs:10:13 | LL | let u = U { a: 0, b: 1 }; | ^ error[E0560]: union `U` has no field named `c` - --> $DIR/union-fields-2.rs:10:29 + --> $DIR/union-fields-2.rs:11:29 | LL | let u = U { a: 0, b: 1, c: 2 }; | ^ `U` does not have this field @@ -19,61 +19,61 @@ LL | let u = U { a: 0, b: 1, c: 2 }; = note: all struct fields are already assigned error[E0784]: union expressions should have exactly one field - --> $DIR/union-fields-2.rs:10:13 + --> $DIR/union-fields-2.rs:11:13 | LL | let u = U { a: 0, b: 1, c: 2 }; | ^ error[E0784]: union expressions should have exactly one field - --> $DIR/union-fields-2.rs:12:13 + --> $DIR/union-fields-2.rs:13:13 | LL | let u = U { ..u }; | ^ error[E0436]: functional record update syntax requires a struct - --> $DIR/union-fields-2.rs:12:19 + --> $DIR/union-fields-2.rs:13:19 | LL | let u = U { ..u }; | ^ error: union patterns should have exactly one field - --> $DIR/union-fields-2.rs:15:9 + --> $DIR/union-fields-2.rs:16:9 | LL | let U {} = u; | ^^^^ error: union patterns should have exactly one field - --> $DIR/union-fields-2.rs:17:9 + --> $DIR/union-fields-2.rs:18:9 | LL | let U { a, b } = u; | ^^^^^^^^^^ error: union patterns should have exactly one field - --> $DIR/union-fields-2.rs:18:9 + --> $DIR/union-fields-2.rs:19:9 | LL | let U { a, b, c } = u; | ^^^^^^^^^^^^^ error[E0026]: union `U` does not have a field named `c` - --> $DIR/union-fields-2.rs:18:19 + --> $DIR/union-fields-2.rs:19:19 | LL | let U { a, b, c } = u; | ^ union `U` does not have this field error: union patterns should have exactly one field - --> $DIR/union-fields-2.rs:20:9 + --> $DIR/union-fields-2.rs:21:9 | LL | let U { .. } = u; | ^^^^^^^^ error: `..` cannot be used in union patterns - --> $DIR/union-fields-2.rs:20:9 + --> $DIR/union-fields-2.rs:21:9 | LL | let U { .. } = u; | ^^^^^^^^ error: `..` cannot be used in union patterns - --> $DIR/union-fields-2.rs:22:9 + --> $DIR/union-fields-2.rs:23:9 | LL | let U { a, .. } = u; | ^^^^^^^^^^^ diff --git a/tests/ui/union/union-overwrite.rs b/tests/ui/union/union-overwrite.rs index cd9a370ff6663..a49d0b5dfe8c8 100644 --- a/tests/ui/union/union-overwrite.rs +++ b/tests/ui/union/union-overwrite.rs @@ -1,4 +1,7 @@ //@ run-pass +//@ reference: items.union.common-storage +//@ reference: items.union.fields.read +//@ reference: type.union.constraint #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/ui/union/union-pat-refutability.rs b/tests/ui/union/union-pat-refutability.rs index 826bd42cd2113..c0d24379c4966 100644 --- a/tests/ui/union/union-pat-refutability.rs +++ b/tests/ui/union/union-pat-refutability.rs @@ -1,4 +1,8 @@ //@ run-pass +//@ reference: items.union.pattern +//@ reference: items.union.pattern.intro +//@ reference: items.union.pattern.safety +//@ reference: items.union.pattern.subpattern #![allow(dead_code)] diff --git a/tests/ui/union/union-unsafe.rs b/tests/ui/union/union-unsafe.rs index beb074f4e8ebc..085031f24e87e 100644 --- a/tests/ui/union/union-unsafe.rs +++ b/tests/ui/union/union-unsafe.rs @@ -1,3 +1,6 @@ +//@ reference: items.union.fields.read-safety +//@ reference: safety.unsafe-union-access +//@ reference: type.union.safety use std::cell::RefCell; use std::mem::ManuallyDrop; use std::ops::Deref; diff --git a/tests/ui/union/union-unsafe.stderr b/tests/ui/union/union-unsafe.stderr index 01f4d95eb649d..6fa01992f5451 100644 --- a/tests/ui/union/union-unsafe.stderr +++ b/tests/ui/union/union-unsafe.stderr @@ -1,5 +1,5 @@ error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:36:6 + --> $DIR/union-unsafe.rs:39:6 | LL | *(u.p) = 13; | ^^^^^ access to union field @@ -7,7 +7,7 @@ LL | *(u.p) = 13; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:50:26 + --> $DIR/union-unsafe.rs:53:26 | LL | let _p = &raw const *(u.p); | ^^^^^ access to union field @@ -15,7 +15,7 @@ LL | let _p = &raw const *(u.p); = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:62:6 + --> $DIR/union-unsafe.rs:65:6 | LL | *u3.a = T::default(); | ^^^^ access to union field @@ -23,7 +23,7 @@ LL | *u3.a = T::default(); = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:68:6 + --> $DIR/union-unsafe.rs:71:6 | LL | *u3.a = T::default(); | ^^^^ access to union field @@ -31,7 +31,7 @@ LL | *u3.a = T::default(); = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:76:13 + --> $DIR/union-unsafe.rs:79:13 | LL | let a = u1.a; | ^^^^ access to union field @@ -39,7 +39,7 @@ LL | let a = u1.a; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:91:29 + --> $DIR/union-unsafe.rs:94:29 | LL | let _a = &raw const vec[u4.a]; | ^^^^ access to union field @@ -47,7 +47,7 @@ LL | let _a = &raw const vec[u4.a]; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:93:14 + --> $DIR/union-unsafe.rs:96:14 | LL | let U1 { a } = u1; | ^ access to union field @@ -55,7 +55,7 @@ LL | let U1 { a } = u1; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:94:20 + --> $DIR/union-unsafe.rs:97:20 | LL | if let U1 { a: 12 } = u1 {} | ^^ access to union field @@ -63,7 +63,7 @@ LL | if let U1 { a: 12 } = u1 {} = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:95:25 + --> $DIR/union-unsafe.rs:98:25 | LL | if let Some(U1 { a: 13 }) = Some(u1) {} | ^^ access to union field @@ -71,7 +71,7 @@ LL | if let Some(U1 { a: 13 }) = Some(u1) {} = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:100:6 + --> $DIR/union-unsafe.rs:103:6 | LL | *u2.a = String::from("new"); | ^^^^ access to union field @@ -79,7 +79,7 @@ LL | *u2.a = String::from("new"); = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:104:6 + --> $DIR/union-unsafe.rs:107:6 | LL | *u3.a = 1; | ^^^^ access to union field @@ -87,7 +87,7 @@ LL | *u3.a = 1; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:108:6 + --> $DIR/union-unsafe.rs:111:6 | LL | *u3.a = String::from("new"); | ^^^^ access to union field @@ -95,7 +95,7 @@ LL | *u3.a = String::from("new"); = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:117:28 + --> $DIR/union-unsafe.rs:120:28 | LL | let _p = &raw const (**a.b).c; | ^^^ access to union field @@ -103,7 +103,7 @@ LL | let _p = &raw const (**a.b).c; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:148:27 + --> $DIR/union-unsafe.rs:151:27 | LL | let _p = &raw const (*a.b).c; | ^^^ access to union field