summaryrefslogtreecommitdiffstats
path: root/tests/ui/union
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/union')
-rw-r--r--tests/ui/union/field_checks.rs10
-rw-r--r--tests/ui/union/field_checks.stderr30
-rw-r--r--tests/ui/union/issue-41073.rs2
-rw-r--r--tests/ui/union/issue-41073.stderr6
-rw-r--r--tests/ui/union/union-copy.rs2
-rw-r--r--tests/ui/union/union-copy.stderr2
-rw-r--r--tests/ui/union/union-derive-clone.mirunsafeck.stderr6
-rw-r--r--tests/ui/union/union-derive-clone.thirunsafeck.stderr6
-rw-r--r--tests/ui/union/union-derive-eq.mirunsafeck.stderr3
-rw-r--r--tests/ui/union/union-derive-eq.thirunsafeck.stderr3
-rw-r--r--tests/ui/union/union-with-drop-fields.mirunsafeck.stderr18
-rw-r--r--tests/ui/union/union-with-drop-fields.rs6
-rw-r--r--tests/ui/union/union-with-drop-fields.thirunsafeck.stderr18
-rw-r--r--tests/ui/union/unresolved-field-isnt-copy.rs8
-rw-r--r--tests/ui/union/unresolved-field-isnt-copy.stderr9
15 files changed, 76 insertions, 53 deletions
diff --git a/tests/ui/union/field_checks.rs b/tests/ui/union/field_checks.rs
index d5d1e44ac..bb4eccb4c 100644
--- a/tests/ui/union/field_checks.rs
+++ b/tests/ui/union/field_checks.rs
@@ -21,15 +21,15 @@ union U24<T> { // OK
}
union U3 {
- a: String, //~ ERROR unions cannot contain fields that may need dropping
+ a: String, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
}
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
+ a: std::cell::RefCell<i32>, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
}
union U4<T> {
- a: T, //~ ERROR unions cannot contain fields that may need dropping
+ a: T, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
}
union U5 { // Having a drop impl is OK
@@ -41,11 +41,11 @@ impl Drop for U5 {
}
union U5Nested { // a nested union that drops is NOT OK
- nest: U5, //~ ERROR unions cannot contain fields that may need dropping
+ nest: U5, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
}
union U5Nested2 { // for now we don't special-case empty arrays
- nest: [U5; 0], //~ ERROR unions cannot contain fields that may need dropping
+ nest: [U5; 0], //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
}
union U6 { // OK
diff --git a/tests/ui/union/field_checks.stderr b/tests/ui/union/field_checks.stderr
index 1f97e97ac..32407a749 100644
--- a/tests/ui/union/field_checks.stderr
+++ b/tests/ui/union/field_checks.stderr
@@ -1,59 +1,59 @@
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/field_checks.rs:24:5
|
LL | a: String,
| ^^^^^^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<String>,
| +++++++++++++++++++++++ +
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/field_checks.rs:28:5
|
LL | a: std::cell::RefCell<i32>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<std::cell::RefCell<i32>>,
| +++++++++++++++++++++++ +
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/field_checks.rs:32:5
|
LL | a: T,
| ^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<T>,
| +++++++++++++++++++++++ +
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/field_checks.rs:44:5
|
LL | nest: U5,
| ^^^^^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | nest: std::mem::ManuallyDrop<U5>,
| +++++++++++++++++++++++ +
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/field_checks.rs:48:5
|
LL | nest: [U5; 0],
| ^^^^^^^^^^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | nest: std::mem::ManuallyDrop<[U5; 0]>,
| +++++++++++++++++++++++ +
diff --git a/tests/ui/union/issue-41073.rs b/tests/ui/union/issue-41073.rs
index 4dfdc606b..f7a82b4e7 100644
--- a/tests/ui/union/issue-41073.rs
+++ b/tests/ui/union/issue-41073.rs
@@ -1,5 +1,5 @@
union Test {
- a: A, //~ ERROR unions cannot contain fields that may need dropping
+ 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 b3887fa0f..ae1c4dfed 100644
--- a/tests/ui/union/issue-41073.stderr
+++ b/tests/ui/union/issue-41073.stderr
@@ -1,11 +1,11 @@
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/issue-41073.rs:2:5
|
LL | a: A,
| ^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<A>,
| +++++++++++++++++++++++ +
diff --git a/tests/ui/union/union-copy.rs b/tests/ui/union/union-copy.rs
index 5c3f8d908..7ad0a11c6 100644
--- a/tests/ui/union/union-copy.rs
+++ b/tests/ui/union/union-copy.rs
@@ -9,6 +9,6 @@ union W {
}
impl Copy for U {} // OK
-impl Copy for W {} //~ ERROR the trait `Copy` may not be implemented for this type
+impl Copy for W {} //~ ERROR the trait `Copy` cannot be implemented for this type
fn main() {}
diff --git a/tests/ui/union/union-copy.stderr b/tests/ui/union/union-copy.stderr
index 53ee4dd2e..ff6fa48db 100644
--- a/tests/ui/union/union-copy.stderr
+++ b/tests/ui/union/union-copy.stderr
@@ -1,4 +1,4 @@
-error[E0204]: the trait `Copy` may not be implemented for this type
+error[E0204]: the trait `Copy` cannot be implemented for this type
--> $DIR/union-copy.rs:12:15
|
LL | a: std::mem::ManuallyDrop<String>
diff --git a/tests/ui/union/union-derive-clone.mirunsafeck.stderr b/tests/ui/union/union-derive-clone.mirunsafeck.stderr
index b80e8b988..4d23d230f 100644
--- a/tests/ui/union/union-derive-clone.mirunsafeck.stderr
+++ b/tests/ui/union/union-derive-clone.mirunsafeck.stderr
@@ -9,7 +9,8 @@ note: required by a bound in `AssertParamIsCopy`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `U1` with `#[derive(Copy)]`
|
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | union U1 {
|
error[E0599]: the method `clone` exists for union `U5<CloneNoCopy>`, but its trait bounds were not satisfied
@@ -34,7 +35,8 @@ LL | #[derive(Clone, Copy)]
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
|
-LL | #[derive(Clone, Copy)]
+LL + #[derive(Clone, Copy)]
+LL | struct CloneNoCopy;
|
error: aborting due to 2 previous errors
diff --git a/tests/ui/union/union-derive-clone.thirunsafeck.stderr b/tests/ui/union/union-derive-clone.thirunsafeck.stderr
index b80e8b988..4d23d230f 100644
--- a/tests/ui/union/union-derive-clone.thirunsafeck.stderr
+++ b/tests/ui/union/union-derive-clone.thirunsafeck.stderr
@@ -9,7 +9,8 @@ note: required by a bound in `AssertParamIsCopy`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `U1` with `#[derive(Copy)]`
|
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | union U1 {
|
error[E0599]: the method `clone` exists for union `U5<CloneNoCopy>`, but its trait bounds were not satisfied
@@ -34,7 +35,8 @@ LL | #[derive(Clone, Copy)]
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
|
-LL | #[derive(Clone, Copy)]
+LL + #[derive(Clone, Copy)]
+LL | struct CloneNoCopy;
|
error: aborting due to 2 previous errors
diff --git a/tests/ui/union/union-derive-eq.mirunsafeck.stderr b/tests/ui/union/union-derive-eq.mirunsafeck.stderr
index 9e55390b5..136cd883e 100644
--- a/tests/ui/union/union-derive-eq.mirunsafeck.stderr
+++ b/tests/ui/union/union-derive-eq.mirunsafeck.stderr
@@ -12,7 +12,8 @@ note: required by a bound in `AssertParamIsEq`
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `PartialEqNotEq` with `#[derive(Eq)]`
|
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct PartialEqNotEq;
|
error: aborting due to previous error
diff --git a/tests/ui/union/union-derive-eq.thirunsafeck.stderr b/tests/ui/union/union-derive-eq.thirunsafeck.stderr
index 9e55390b5..136cd883e 100644
--- a/tests/ui/union/union-derive-eq.thirunsafeck.stderr
+++ b/tests/ui/union/union-derive-eq.thirunsafeck.stderr
@@ -12,7 +12,8 @@ note: required by a bound in `AssertParamIsEq`
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `PartialEqNotEq` with `#[derive(Eq)]`
|
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct PartialEqNotEq;
|
error: aborting due to previous error
diff --git a/tests/ui/union/union-with-drop-fields.mirunsafeck.stderr b/tests/ui/union/union-with-drop-fields.mirunsafeck.stderr
index 93fe996d2..9861a21cb 100644
--- a/tests/ui/union/union-with-drop-fields.mirunsafeck.stderr
+++ b/tests/ui/union/union-with-drop-fields.mirunsafeck.stderr
@@ -1,35 +1,35 @@
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/union-with-drop-fields.rs:11:5
|
LL | a: String,
| ^^^^^^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<String>,
| +++++++++++++++++++++++ +
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/union-with-drop-fields.rs:19:5
|
LL | a: S,
| ^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<S>,
| +++++++++++++++++++++++ +
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/union-with-drop-fields.rs:24:5
|
LL | a: T,
| ^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<T>,
| +++++++++++++++++++++++ +
diff --git a/tests/ui/union/union-with-drop-fields.rs b/tests/ui/union/union-with-drop-fields.rs
index a7a8b69e7..9720830fb 100644
--- a/tests/ui/union/union-with-drop-fields.rs
+++ b/tests/ui/union/union-with-drop-fields.rs
@@ -8,7 +8,7 @@ union U {
}
union W {
- a: String, //~ ERROR unions cannot contain fields that may need dropping
+ a: String, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
b: String, // OK, only one field is reported
}
@@ -16,12 +16,12 @@ struct S(String);
// `S` doesn't implement `Drop` trait, but still has non-trivial destructor
union Y {
- a: S, //~ ERROR unions cannot contain fields that may need dropping
+ a: S, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
}
// We don't know if `T` is trivially-destructable or not until trans
union J<T> {
- a: T, //~ ERROR unions cannot contain fields that may need dropping
+ a: T, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
}
union H<T: Copy> {
diff --git a/tests/ui/union/union-with-drop-fields.thirunsafeck.stderr b/tests/ui/union/union-with-drop-fields.thirunsafeck.stderr
index 93fe996d2..9861a21cb 100644
--- a/tests/ui/union/union-with-drop-fields.thirunsafeck.stderr
+++ b/tests/ui/union/union-with-drop-fields.thirunsafeck.stderr
@@ -1,35 +1,35 @@
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/union-with-drop-fields.rs:11:5
|
LL | a: String,
| ^^^^^^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<String>,
| +++++++++++++++++++++++ +
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/union-with-drop-fields.rs:19:5
|
LL | a: S,
| ^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<S>,
| +++++++++++++++++++++++ +
-error[E0740]: unions cannot contain fields that may need dropping
+error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/union-with-drop-fields.rs:24:5
|
LL | a: T,
| ^^^^
|
- = note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
-help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
+ = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
+help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<T>,
| +++++++++++++++++++++++ +
diff --git a/tests/ui/union/unresolved-field-isnt-copy.rs b/tests/ui/union/unresolved-field-isnt-copy.rs
new file mode 100644
index 000000000..7a6d79b2f
--- /dev/null
+++ b/tests/ui/union/unresolved-field-isnt-copy.rs
@@ -0,0 +1,8 @@
+// Unresolved fields are not copy, but also shouldn't report an extra E0740.
+
+pub union Foo {
+ x: *const Missing,
+ //~^ ERROR cannot find type `Missing` in this scope
+}
+
+fn main() {}
diff --git a/tests/ui/union/unresolved-field-isnt-copy.stderr b/tests/ui/union/unresolved-field-isnt-copy.stderr
new file mode 100644
index 000000000..22301582e
--- /dev/null
+++ b/tests/ui/union/unresolved-field-isnt-copy.stderr
@@ -0,0 +1,9 @@
+error[E0412]: cannot find type `Missing` in this scope
+ --> $DIR/unresolved-field-isnt-copy.rs:4:15
+ |
+LL | x: *const Missing,
+ | ^^^^^^^ not found in this scope
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0412`.