Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/ui/union/access_union_field.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ reference: items.union.fields.read-safety
//@ reference: type.union.safety
#![allow(unused_variables)]

union Foo {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/union/access_union_field.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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
|
= 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
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/union/field_checks.rs
Original file line number Diff line number Diff line change
@@ -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
Comment thread
DanielEScherzer marked this conversation as resolved.
use std::mem::ManuallyDrop;

union U1 { // OK
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/union/field_checks.stderr
Original file line number Diff line number Diff line change
@@ -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,
| ^^^^^^^^^
Expand All @@ -11,7 +11,7 @@ LL | a: std::mem::ManuallyDrop<String>,
| +++++++++++++++++++++++ +

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<i32>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -23,7 +23,7 @@ LL | a: std::mem::ManuallyDrop<std::cell::RefCell<i32>>,
| +++++++++++++++++++++++ +

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,
| ^^^^
Expand All @@ -35,7 +35,7 @@ LL | a: std::mem::ManuallyDrop<T>,
| +++++++++++++++++++++++ +

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,
| ^^^^^^^^
Expand All @@ -47,7 +47,7 @@ LL | nest: std::mem::ManuallyDrop<U5>,
| +++++++++++++++++++++++ +

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],
| ^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/union/issue-41073.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/union/issue-41073.stderr
Original file line number Diff line number Diff line change
@@ -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,
| ^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/union/issue-81199.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ reference: items.union.field-restrictions
//@ reference: type.union.constraint
#[repr(C)]
union PtrRepr<T: ?Sized> {
const_ptr: *const T,
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/union/issue-81199.stderr
Original file line number Diff line number Diff line change
@@ -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<T>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -11,14 +11,14 @@ LL | components: std::mem::ManuallyDrop<PtrComponents<T>>,
| +++++++++++++++++++++++ +

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<T>,
| ^^^^^^^^^^^^^^^^ 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<T: Pointee + ?Sized> {
| ^^^^^^^ required by this bound in `PtrComponents`
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/union/issue-99375.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ check-pass
//@ reference: items.union.field-copy
//@ reference: items.union.field-tuple

union URes<R: Copy> {
uninit: (),
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/union/union-assignop.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ reference: items.union.fields.read-safety
//@ reference: items.union.fields.write-safety
use std::ops::AddAssign;
use std::mem::ManuallyDrop;

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/union/union-assignop.stderr
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
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
|
= 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
|
= 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
|
= 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
|
= 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
|
= 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
Expand Down
1 change: 1 addition & 0 deletions tests/ui/union/union-backcomp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-pass
//@ reference: lex.keywords.weak.union

#![allow(path_statements)]
#![allow(dead_code)]
Expand Down
1 change: 1 addition & 0 deletions tests/ui/union/union-borrow-move-parent-sibling.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ reference: items.union.ref.borrow
#![allow(unused)]

use std::ops::{Deref, DerefMut};
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/union/union-borrow-move-parent-sibling.stderr
Original file line number Diff line number Diff line change
@@ -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`)
Expand All @@ -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<u8>, MockVec<u8>), MockVec<u8>)>`
--> $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<u8>, MockVec<u8>)`, which does not implement the `Copy` trait
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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`)
Expand All @@ -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<u8>, MockVec<u8>), MockVec<u8>)>`
--> $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<u8>`, which does not implement the `Copy` trait
|
note: if `MockVec<u8>` 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<T> {
| ^^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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`)
Expand Down
1 change: 1 addition & 0 deletions tests/ui/union/union-copy.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ reference: lang-types.copy.constraint
#[derive(Clone)]
union U {
a: u8
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/union/union-copy.stderr
Original file line number Diff line number Diff line change
@@ -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<String>
| --------------------------------- this field does not implement `Copy`
Expand All @@ -8,7 +8,7 @@ LL | impl Copy for W {}
| ^
|
note: the `Copy` impl for `ManuallyDrop<String>` requires that `String: Copy`
--> $DIR/union-copy.rs:8:8
--> $DIR/union-copy.rs:9:8
|
LL | a: std::mem::ManuallyDrop<String>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions tests/ui/union/union-drop-assign.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-pass
//@ reference: items.union.drop
#![allow(unused_assignments)]

// Drop works for union itself.
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/union/union-drop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ run-pass
//@ reference: destructors.manually-suppressing
//@ reference: items.union.drop
Comment thread
DanielEScherzer marked this conversation as resolved.

#![allow(dead_code)]
#![allow(unused_variables)]
Expand Down
1 change: 1 addition & 0 deletions tests/ui/union/union-empty.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ reference: items.union.fieldless
union U {} //~ ERROR unions cannot have zero fields

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/union/union-empty.stderr
Original file line number Diff line number Diff line change
@@ -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 {}
| ^^^^^^^^^^
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/union/union-fields-2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//@ reference: expr.struct.field.union-constraint
//@ reference: items.union.init.intro
Comment thread
DanielEScherzer marked this conversation as resolved.
//@ reference: items.union.pattern.one-field
//@ reference: patterns.struct.constraint-union
union U {
a: u8,
b: u16,
Expand Down
Loading
Loading