From 9a8b45df34d1e3c932d99d7f4af8923201cc1bf4 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Wed, 18 Feb 2026 13:21:49 -0800 Subject: [PATCH] tests/ui/union: add annotations for reference rules --- tests/ui/union/access_union_field.rs | 2 ++ tests/ui/union/access_union_field.stderr | 4 +-- tests/ui/union/field_checks.rs | 7 +++++ tests/ui/union/field_checks.stderr | 10 +++---- tests/ui/union/issue-41073.rs | 2 ++ tests/ui/union/issue-41073.stderr | 2 +- tests/ui/union/issue-81199.rs | 2 ++ tests/ui/union/issue-81199.stderr | 6 ++-- tests/ui/union/issue-99375.rs | 2 ++ tests/ui/union/union-assignop.rs | 2 ++ tests/ui/union/union-assignop.stderr | 12 ++++---- tests/ui/union/union-backcomp.rs | 1 + .../union/union-borrow-move-parent-sibling.rs | 1 + .../union-borrow-move-parent-sibling.stderr | 20 ++++++------- tests/ui/union/union-copy.rs | 1 + tests/ui/union/union-copy.stderr | 4 +-- tests/ui/union/union-drop-assign.rs | 1 + tests/ui/union/union-drop.rs | 2 ++ tests/ui/union/union-empty.rs | 1 + tests/ui/union/union-empty.stderr | 2 +- tests/ui/union/union-fields-2.rs | 4 +++ tests/ui/union/union-fields-2.stderr | 26 ++++++++--------- tests/ui/union/union-inherent-method.rs | 1 + tests/ui/union/union-manuallydrop-rpass.rs | 2 ++ tests/ui/union/union-overwrite.rs | 2 ++ tests/ui/union/union-packed.rs | 1 + tests/ui/union/union-pat-in-param.rs | 1 + tests/ui/union/union-pat-in-param.stderr | 4 +-- tests/ui/union/union-pat-refutability.rs | 3 ++ tests/ui/union/union-trait-impl.rs | 1 + tests/ui/union/union-transmute.rs | 2 ++ tests/ui/union/union-unsafe.rs | 5 ++++ tests/ui/union/union-unsafe.stderr | 28 +++++++++---------- tests/ui/union/union-with-drop-fields.rs | 1 + tests/ui/union/union-with-drop-fields.stderr | 6 ++-- tests/ui/union/union_destructure.rs | 1 + 36 files changed, 110 insertions(+), 62 deletions(-) diff --git a/tests/ui/union/access_union_field.rs b/tests/ui/union/access_union_field.rs index 4183119725eca..2fbb924e390e0 100644 --- a/tests/ui/union/access_union_field.rs +++ b/tests/ui/union/access_union_field.rs @@ -1,3 +1,5 @@ +//@ reference: items.union.fields.read-safety +//@ reference: type.union.safety #![allow(unused_variables)] union Foo { diff --git a/tests/ui/union/access_union_field.stderr b/tests/ui/union/access_union_field.stderr index 4c46bb44a1d33..c56a6067e45bc 100644 --- a/tests/ui/union/access_union_field.stderr +++ b/tests/ui/union/access_union_field.stderr @@ -1,5 +1,5 @@ error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/access_union_field.rs:10:13 + --> $DIR/access_union_field.rs:12:13 | LL | let a = foo.bar; | ^^^^^^^ access to union field @@ -7,7 +7,7 @@ LL | let a = foo.bar; = 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/access_union_field.rs:11:13 + --> $DIR/access_union_field.rs:13:13 | LL | let b = foo.baz; | ^^^^^^^ access to union field diff --git a/tests/ui/union/field_checks.rs b/tests/ui/union/field_checks.rs index bb4eccb4cf896..551ae2d6fbcbe 100644 --- a/tests/ui/union/field_checks.rs +++ b/tests/ui/union/field_checks.rs @@ -1,3 +1,10 @@ +//@ reference: items.union.drop +//@ 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..b9440a12602db 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:31: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:35: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:39: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:51: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:55:5 | LL | nest: [U5; 0], | ^^^^^^^^^^^^^ diff --git a/tests/ui/union/issue-41073.rs b/tests/ui/union/issue-41073.rs index f7a82b4e7cf5d..3536b9fd20375 100644 --- a/tests/ui/union/issue-41073.rs +++ b/tests/ui/union/issue-41073.rs @@ -1,3 +1,5 @@ +//@ reference: items.union.field-restrictions +//@ reference: type.union.constraint union Test { a: A, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union b: B diff --git a/tests/ui/union/issue-41073.stderr b/tests/ui/union/issue-41073.stderr index c9b6903b1bfba..d66e3753ae658 100644 --- a/tests/ui/union/issue-41073.stderr +++ b/tests/ui/union/issue-41073.stderr @@ -1,5 +1,5 @@ error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/issue-41073.rs:2:5 + --> $DIR/issue-41073.rs:4:5 | LL | a: A, | ^^^^ diff --git a/tests/ui/union/issue-81199.rs b/tests/ui/union/issue-81199.rs index 2083ee15d87bd..89460f2f4b43f 100644 --- a/tests/ui/union/issue-81199.rs +++ b/tests/ui/union/issue-81199.rs @@ -1,3 +1,5 @@ +//@ reference: items.union.field-restrictions +//@ reference: type.union.constraint #[repr(C)] union PtrRepr { const_ptr: *const T, diff --git a/tests/ui/union/issue-81199.stderr b/tests/ui/union/issue-81199.stderr index 46f5de8d4fd8a..a36aa4bf98c46 100644 --- a/tests/ui/union/issue-81199.stderr +++ b/tests/ui/union/issue-81199.stderr @@ -1,5 +1,5 @@ error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/issue-81199.rs:5:5 + --> $DIR/issue-81199.rs:7:5 | LL | components: PtrComponents, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,14 +11,14 @@ LL | components: std::mem::ManuallyDrop>, | +++++++++++++++++++++++ + error[E0277]: the trait bound `T: Pointee` is not satisfied - --> $DIR/issue-81199.rs:5:17 + --> $DIR/issue-81199.rs:7:17 | LL | components: PtrComponents, | ^^^^^^^^^^^^^^^^ the trait `Pointee` is not implemented for `T` | = note: `T` implements similarly named trait `std::ptr::Pointee`, but not `Pointee` note: required by a bound in `PtrComponents` - --> $DIR/issue-81199.rs:11:25 + --> $DIR/issue-81199.rs:13:25 | LL | struct PtrComponents { | ^^^^^^^ required by this bound in `PtrComponents` diff --git a/tests/ui/union/issue-99375.rs b/tests/ui/union/issue-99375.rs index ead083b21b1e9..cc0a7adbaf8db 100644 --- a/tests/ui/union/issue-99375.rs +++ b/tests/ui/union/issue-99375.rs @@ -1,4 +1,6 @@ //@ check-pass +//@ reference: items.union.field-copy +//@ reference: items.union.field-tuple union URes { uninit: (), diff --git a/tests/ui/union/union-assignop.rs b/tests/ui/union/union-assignop.rs index 6122aef0565e0..fdffa4a535ff0 100644 --- a/tests/ui/union/union-assignop.rs +++ b/tests/ui/union/union-assignop.rs @@ -1,3 +1,5 @@ +//@ reference: items.union.fields.read-safety +//@ reference: items.union.fields.write-safety use std::ops::AddAssign; use std::mem::ManuallyDrop; diff --git a/tests/ui/union/union-assignop.stderr b/tests/ui/union/union-assignop.stderr index 6b2ebfb509961..087c599dbc1ae 100644 --- a/tests/ui/union/union-assignop.stderr +++ b/tests/ui/union/union-assignop.stderr @@ -1,5 +1,5 @@ error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-assignop.rs:16:5 + --> $DIR/union-assignop.rs:18:5 | LL | foo.a += 5; | ^^^^^ access to union field @@ -7,7 +7,7 @@ LL | foo.a += 5; = 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-assignop.rs:17:6 + --> $DIR/union-assignop.rs:19:6 | LL | *foo.b += NonCopy; | ^^^^^ access to union field @@ -15,7 +15,7 @@ LL | *foo.b += NonCopy; = 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-assignop.rs:18:6 + --> $DIR/union-assignop.rs:20:6 | LL | *foo.b = NonCopy; | ^^^^^ access to union field @@ -23,7 +23,7 @@ LL | *foo.b = NonCopy; = 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-assignop.rs:20:5 + --> $DIR/union-assignop.rs:22:5 | LL | foo.a; | ^^^^^ access to union field @@ -31,7 +31,7 @@ LL | foo.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-assignop.rs:22:5 + --> $DIR/union-assignop.rs:24:5 | LL | foo.b; | ^^^^^ access to union field @@ -39,7 +39,7 @@ LL | foo.b; = 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-assignop.rs:24:13 + --> $DIR/union-assignop.rs:26:13 | LL | foo.b = foo.b; | ^^^^^ access to union field 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-borrow-move-parent-sibling.rs b/tests/ui/union/union-borrow-move-parent-sibling.rs index 5b0b44232e411..435fa7fbd1540 100644 --- a/tests/ui/union/union-borrow-move-parent-sibling.rs +++ b/tests/ui/union/union-borrow-move-parent-sibling.rs @@ -1,3 +1,4 @@ +//@ reference: items.union.ref.borrow #![allow(unused)] use std::ops::{Deref, DerefMut}; diff --git a/tests/ui/union/union-borrow-move-parent-sibling.stderr b/tests/ui/union/union-borrow-move-parent-sibling.stderr index 461ee407e2ddb..0655cd0908113 100644 --- a/tests/ui/union/union-borrow-move-parent-sibling.stderr +++ b/tests/ui/union/union-borrow-move-parent-sibling.stderr @@ -1,5 +1,5 @@ error[E0502]: cannot borrow `u` (via `u.y`) as immutable because it is also borrowed as mutable (via `u.x`) - --> $DIR/union-borrow-move-parent-sibling.rs:53:13 + --> $DIR/union-borrow-move-parent-sibling.rs:54:13 | LL | let a = &mut (*u.x).0; | --- mutable borrow occurs here (via `u.x`) @@ -11,7 +11,7 @@ LL | use_borrow(a); = note: `u.y` is a field of the union `U`, so it overlaps the field `u.x` error[E0507]: cannot move out of dereference of `ManuallyDrop<((MockVec, MockVec), MockVec)>` - --> $DIR/union-borrow-move-parent-sibling.rs:59:13 + --> $DIR/union-borrow-move-parent-sibling.rs:60:13 | LL | let a = u.x.0; | ^^^^^ move occurs because value has type `(MockVec, MockVec)`, which does not implement the `Copy` trait @@ -22,7 +22,7 @@ LL | let a = &u.x.0; | + error[E0382]: use of moved value: `u` - --> $DIR/union-borrow-move-parent-sibling.rs:61:13 + --> $DIR/union-borrow-move-parent-sibling.rs:62:13 | LL | let u = U { x: ManuallyDrop::new(((MockVec::new(), MockVec::new()), MockVec::new())) }; | - move occurs because `u` has type `U`, which does not implement the `Copy` trait @@ -33,7 +33,7 @@ LL | let b = u.y; | ^^^ value used here after move | note: if `U` implemented `Clone`, you could clone the value - --> $DIR/union-borrow-move-parent-sibling.rs:43:1 + --> $DIR/union-borrow-move-parent-sibling.rs:44:1 | LL | union U { | ^^^^^^^ consider implementing `Clone` for this type @@ -42,7 +42,7 @@ LL | let a = u.x; | --- you could clone this value error[E0502]: cannot borrow `u` (via `u.y`) as immutable because it is also borrowed as mutable (via `u.x`) - --> $DIR/union-borrow-move-parent-sibling.rs:67:13 + --> $DIR/union-borrow-move-parent-sibling.rs:68:13 | LL | let a = &mut ((*u.x).0).0; | --- mutable borrow occurs here (via `u.x`) @@ -54,13 +54,13 @@ LL | use_borrow(a); = note: `u.y` is a field of the union `U`, so it overlaps the field `u.x` error[E0507]: cannot move out of dereference of `ManuallyDrop<((MockVec, MockVec), MockVec)>` - --> $DIR/union-borrow-move-parent-sibling.rs:73:13 + --> $DIR/union-borrow-move-parent-sibling.rs:74:13 | LL | let a = (u.x.0).0; | ^^^^^^^^^ move occurs because value has type `MockVec`, which does not implement the `Copy` trait | note: if `MockVec` implemented `Clone`, you could clone the value - --> $DIR/union-borrow-move-parent-sibling.rs:25:1 + --> $DIR/union-borrow-move-parent-sibling.rs:26:1 | LL | struct MockVec { | ^^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type @@ -73,7 +73,7 @@ LL | let a = &(u.x.0).0; | + error[E0382]: use of moved value: `u` - --> $DIR/union-borrow-move-parent-sibling.rs:75:13 + --> $DIR/union-borrow-move-parent-sibling.rs:76:13 | LL | let u = U { x: ManuallyDrop::new(((MockVec::new(), MockVec::new()), MockVec::new())) }; | - move occurs because `u` has type `U`, which does not implement the `Copy` trait @@ -84,7 +84,7 @@ LL | let b = u.y; | ^^^ value used here after move | note: if `U` implemented `Clone`, you could clone the value - --> $DIR/union-borrow-move-parent-sibling.rs:43:1 + --> $DIR/union-borrow-move-parent-sibling.rs:44:1 | LL | union U { | ^^^^^^^ consider implementing `Clone` for this type @@ -93,7 +93,7 @@ LL | let a = u.x; | --- you could clone this value error[E0502]: cannot borrow `u` (via `u.x`) as immutable because it is also borrowed as mutable (via `u.y`) - --> $DIR/union-borrow-move-parent-sibling.rs:81:13 + --> $DIR/union-borrow-move-parent-sibling.rs:82:13 | LL | let a = &mut *u.y; | --- mutable borrow occurs here (via `u.y`) 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-assign.rs b/tests/ui/union/union-drop-assign.rs index 710a6f6205e01..ac3120fc2f25c 100644 --- a/tests/ui/union/union-drop-assign.rs +++ b/tests/ui/union/union-drop-assign.rs @@ -1,4 +1,5 @@ //@ run-pass +//@ reference: items.union.drop #![allow(unused_assignments)] // Drop works for union itself. diff --git a/tests/ui/union/union-drop.rs b/tests/ui/union/union-drop.rs index 9a2911599dfe2..4e3ce06014c82 100644 --- a/tests/ui/union/union-drop.rs +++ b/tests/ui/union/union-drop.rs @@ -1,4 +1,6 @@ //@ run-pass +//@ reference: destructors.manually-suppressing +//@ 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..2c4dc241bc43a 100644 --- a/tests/ui/union/union-fields-2.rs +++ b/tests/ui/union/union-fields-2.rs @@ -1,3 +1,7 @@ +//@ reference: expr.struct.field.union-constraint +//@ reference: items.union.init.intro +//@ reference: items.union.pattern.one-field +//@ reference: patterns.struct.constraint-union 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..4cfd2271f3f79 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:11: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:13: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:14: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:14: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:16: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:16: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:19: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:21: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:22: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:22: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:24:9 | LL | let U { .. } = u; | ^^^^^^^^ error: `..` cannot be used in union patterns - --> $DIR/union-fields-2.rs:20:9 + --> $DIR/union-fields-2.rs:24:9 | LL | let U { .. } = u; | ^^^^^^^^ error: `..` cannot be used in union patterns - --> $DIR/union-fields-2.rs:22:9 + --> $DIR/union-fields-2.rs:26:9 | LL | let U { a, .. } = u; | ^^^^^^^^^^^ diff --git a/tests/ui/union/union-inherent-method.rs b/tests/ui/union/union-inherent-method.rs index a3f962fb87211..86a62ff18cd3d 100644 --- a/tests/ui/union/union-inherent-method.rs +++ b/tests/ui/union/union-inherent-method.rs @@ -1,4 +1,5 @@ //@ run-pass +//@ reference: items.impl.inherent.associated-items.allowed-items union U { a: u8, diff --git a/tests/ui/union/union-manuallydrop-rpass.rs b/tests/ui/union/union-manuallydrop-rpass.rs index c1be39c20e613..f69fc2d36fe1e 100644 --- a/tests/ui/union/union-manuallydrop-rpass.rs +++ b/tests/ui/union/union-manuallydrop-rpass.rs @@ -1,4 +1,6 @@ //@ run-pass +//@ reference: items.union.field-copy +//@ reference: items.union.field-manually-drop #![allow(dead_code)] use std::mem::needs_drop; diff --git a/tests/ui/union/union-overwrite.rs b/tests/ui/union/union-overwrite.rs index cd9a370ff6663..5cb6152ced33a 100644 --- a/tests/ui/union/union-overwrite.rs +++ b/tests/ui/union/union-overwrite.rs @@ -1,4 +1,6 @@ //@ run-pass +//@ reference: items.union.common-storage +//@ reference: items.union.fields.read #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/ui/union/union-packed.rs b/tests/ui/union/union-packed.rs index b1ab211eae829..790c82364060f 100644 --- a/tests/ui/union/union-packed.rs +++ b/tests/ui/union/union-packed.rs @@ -1,4 +1,5 @@ //@ run-pass +//@ reference: layout.repr.alignment.intro #![allow(dead_code)] #![allow(non_snake_case)] diff --git a/tests/ui/union/union-pat-in-param.rs b/tests/ui/union/union-pat-in-param.rs index 8454bfb20dcb8..6a65a5c060006 100644 --- a/tests/ui/union/union-pat-in-param.rs +++ b/tests/ui/union/union-pat-in-param.rs @@ -1,3 +1,4 @@ +//@ reference: items.union.pattern.safety union U { a: &'static i32, b: usize, diff --git a/tests/ui/union/union-pat-in-param.stderr b/tests/ui/union/union-pat-in-param.stderr index b9709b7cc9bf1..b1eb70f79bcaf 100644 --- a/tests/ui/union/union-pat-in-param.stderr +++ b/tests/ui/union/union-pat-in-param.stderr @@ -1,5 +1,5 @@ error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-pat-in-param.rs:6:12 + --> $DIR/union-pat-in-param.rs:7:12 | LL | fn fun(U { a }: U) { | ^ access to union field @@ -7,7 +7,7 @@ LL | fn fun(U { a }: U) { = 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-pat-in-param.rs:14:24 + --> $DIR/union-pat-in-param.rs:15:24 | LL | let closure = |U { a }| { | ^ access to union field diff --git a/tests/ui/union/union-pat-refutability.rs b/tests/ui/union/union-pat-refutability.rs index 826bd42cd2113..3f4c06f1e03e5 100644 --- a/tests/ui/union/union-pat-refutability.rs +++ b/tests/ui/union/union-pat-refutability.rs @@ -1,4 +1,7 @@ //@ run-pass +//@ reference: items.union.pattern.intro +//@ reference: items.union.pattern.safety +//@ reference: patterns.struct.refutable #![allow(dead_code)] diff --git a/tests/ui/union/union-trait-impl.rs b/tests/ui/union/union-trait-impl.rs index d48ae18dd0e5e..238189ea82a81 100644 --- a/tests/ui/union/union-trait-impl.rs +++ b/tests/ui/union/union-trait-impl.rs @@ -1,4 +1,5 @@ //@ run-pass +//@ reference: items.union.ref.use use std::fmt; diff --git a/tests/ui/union/union-transmute.rs b/tests/ui/union/union-transmute.rs index 72ac4a85d593b..879ee7a23dbd8 100644 --- a/tests/ui/union/union-transmute.rs +++ b/tests/ui/union/union-transmute.rs @@ -1,4 +1,6 @@ //@ run-pass +//@ reference: items.union.common-storage +//@ reference: type.union.access union U { a: (u8, u8), diff --git a/tests/ui/union/union-unsafe.rs b/tests/ui/union/union-unsafe.rs index beb074f4e8ebc..62d307927cccd 100644 --- a/tests/ui/union/union-unsafe.rs +++ b/tests/ui/union/union-unsafe.rs @@ -1,3 +1,8 @@ +//@ reference: items.union.fields.read-safety +//@ reference: items.union.fields.write-safety +//@ reference: items.union.pattern.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..36543085ba82c 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:41: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:55: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:67: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:73: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:81: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:96: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:98: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:99: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:100: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:105: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:109: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:113: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:122: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:153:27 | LL | let _p = &raw const (*a.b).c; | ^^^ access to union field diff --git a/tests/ui/union/union-with-drop-fields.rs b/tests/ui/union/union-with-drop-fields.rs index ae147e9bd2b5d..949b478f2ecb4 100644 --- a/tests/ui/union/union-with-drop-fields.rs +++ b/tests/ui/union/union-with-drop-fields.rs @@ -1,3 +1,4 @@ +//@ reference: items.union.field-restrictions #![allow(dead_code)] union U { diff --git a/tests/ui/union/union-with-drop-fields.stderr b/tests/ui/union/union-with-drop-fields.stderr index 6328be565408e..290fcec201ca2 100644 --- a/tests/ui/union/union-with-drop-fields.stderr +++ b/tests/ui/union/union-with-drop-fields.stderr @@ -1,5 +1,5 @@ error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/union-with-drop-fields.rs:8:5 + --> $DIR/union-with-drop-fields.rs:9: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/union-with-drop-fields.rs:16:5 + --> $DIR/union-with-drop-fields.rs:17:5 | LL | a: S, | ^^^^ @@ -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/union-with-drop-fields.rs:21:5 + --> $DIR/union-with-drop-fields.rs:22:5 | LL | a: T, | ^^^^ diff --git a/tests/ui/union/union_destructure.rs b/tests/ui/union/union_destructure.rs index e7095926eb164..9c445c9986296 100644 --- a/tests/ui/union/union_destructure.rs +++ b/tests/ui/union/union_destructure.rs @@ -1,4 +1,5 @@ //@ run-pass +//@ reference: items.union.pattern.safety #![allow(unreachable_patterns)] #[derive(Copy, Clone)]