about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorDaniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>2022-02-15 20:16:19 +0100
committerDaniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>2022-02-16 13:29:00 +0100
commit6d2cdbec3ef6e5460753986372ed898a1b3bc553 (patch)
treef7fd3ce176fe84e15647e17cd1accd9998d9b9fd /compiler
parent6421a499a50adbaa7b5d0234bdd4817d970f0933 (diff)
downloadrust-6d2cdbec3ef6e5460753986372ed898a1b3bc553.tar.gz
rust-6d2cdbec3ef6e5460753986372ed898a1b3bc553.zip
Add mentions to `Copy` for `union` fields
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_typeck/src/check/check.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs
index 423abc3227d..ca2e75886c7 100644
--- a/compiler/rustc_typeck/src/check/check.rs
+++ b/compiler/rustc_typeck/src/check/check.rs
@@ -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()),