Add mentions to Copy for union fields

This commit is contained in:
Daniel Henry-Mantilla 2022-02-15 20:16:19 +01:00
parent 6421a499a5
commit 6d2cdbec3e
10 changed files with 44 additions and 29 deletions

View File

@ -382,10 +382,15 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
tcx.sess,
field_span,
E0740,
"unions may not contain fields that need dropping"
"unions cannot contain fields that may need dropping"
)
.note(
"a type is guaranteed not to need dropping \
when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type",
)
.multipart_suggestion_verbose(
"wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped",
"when the type does not implement `Copy`, \
wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped",
vec![
(ty_span.shrink_to_lo(), format!("std::mem::ManuallyDrop<")),
(ty_span.shrink_to_hi(), ">".into()),

View File

@ -13,7 +13,7 @@ union U22<T> { // OK
}
union U3 {
a: String, //~ ERROR unions may not contain fields that need dropping
a: String, //~ ERROR unions cannot contain fields that may need dropping
}
union U32 { // field that does not drop but is not `Copy`, either -- this is the real feature gate test!
@ -21,7 +21,7 @@ union U32 { // field that does not drop but is not `Copy`, either -- this is the
}
union U4<T> {
a: T, //~ ERROR unions may not contain fields that need dropping
a: T, //~ ERROR unions cannot contain fields that may need dropping
}
union U5 { // Having a drop impl is OK

View File

@ -7,24 +7,26 @@ LL | a: std::cell::RefCell<i32>,
= note: see issue #55149 <https://github.com/rust-lang/rust/issues/55149> for more information
= help: add `#![feature(untagged_unions)]` to the crate attributes to enable
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/feature-gate-untagged_unions.rs:16:5
|
LL | a: String,
| ^^^^^^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | a: std::mem::ManuallyDrop<String>,
| +++++++++++++++++++++++ +
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/feature-gate-untagged_unions.rs:24:5
|
LL | a: T,
| ^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | a: std::mem::ManuallyDrop<T>,
| +++++++++++++++++++++++ +

View File

@ -1,7 +1,7 @@
#![feature(untagged_unions)]
union Test {
a: A, //~ ERROR unions may not contain fields that need dropping
a: A, //~ ERROR unions cannot contain fields that may need dropping
b: B
}

View File

@ -1,10 +1,11 @@
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/issue-41073.rs:4:5
|
LL | a: A,
| ^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | a: std::mem::ManuallyDrop<A>,
| +++++++++++++++++++++++ +

View File

@ -4,7 +4,7 @@
#![feature(untagged_unions)]
union Foo {
bar: Bar, //~ ERROR unions may not contain fields that need dropping
bar: Bar, //~ ERROR unions cannot contain fields that may need dropping
}
union Bar {

View File

@ -1,10 +1,11 @@
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/union-custom-drop.rs:7:5
|
LL | bar: Bar,
| ^^^^^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | bar: std::mem::ManuallyDrop<Bar>,
| +++++++++++++++++++++++ +

View File

@ -1,32 +1,35 @@
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/union-with-drop-fields.rs:11:5
|
LL | a: String,
| ^^^^^^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | a: std::mem::ManuallyDrop<String>,
| +++++++++++++++++++++++ +
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/union-with-drop-fields.rs:19:5
|
LL | a: S,
| ^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | a: std::mem::ManuallyDrop<S>,
| +++++++++++++++++++++++ +
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/union-with-drop-fields.rs:24:5
|
LL | a: T,
| ^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | a: std::mem::ManuallyDrop<T>,
| +++++++++++++++++++++++ +

View File

@ -8,7 +8,7 @@ union U {
}
union W {
a: String, //~ ERROR unions may not contain fields that need dropping
a: String, //~ ERROR unions cannot contain fields that may need dropping
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 may not contain fields that need dropping
a: S, //~ ERROR unions cannot contain fields that may need dropping
}
// We don't know if `T` is trivially-destructable or not until trans
union J<T> {
a: T, //~ ERROR unions may not contain fields that need dropping
a: T, //~ ERROR unions cannot contain fields that may need dropping
}
union H<T: Copy> {

View File

@ -1,32 +1,35 @@
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/union-with-drop-fields.rs:11:5
|
LL | a: String,
| ^^^^^^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | a: std::mem::ManuallyDrop<String>,
| +++++++++++++++++++++++ +
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/union-with-drop-fields.rs:19:5
|
LL | a: S,
| ^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | a: std::mem::ManuallyDrop<S>,
| +++++++++++++++++++++++ +
error[E0740]: unions may not contain fields that need dropping
error[E0740]: unions cannot contain fields that may need dropping
--> $DIR/union-with-drop-fields.rs:24:5
|
LL | a: T,
| ^^^^
|
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
= 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
|
LL | a: std::mem::ManuallyDrop<T>,
| +++++++++++++++++++++++ +