about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorLucas Kent <rubickent@gmail.com>2021-11-15 14:47:36 +1100
committerLucas Kent <rubickent@gmail.com>2021-11-15 14:51:56 +1100
commit62acf7f96def600de3239cb93b62d07e9b514276 (patch)
treebdf103e7e71bd5a51cf3527f4acf6d5c5876c51c /compiler
parentf980f813e189b8568eab93311fcc4effa2cffec3 (diff)
downloadrust-62acf7f96def600de3239cb93b62d07e9b514276.tar.gz
rust-62acf7f96def600de3239cb93b62d07e9b514276.zip
feedback
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_typeck/src/check/check.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs
index 335814f8627..bb1d9744e66 100644
--- a/compiler/rustc_typeck/src/check/check.rs
+++ b/compiler/rustc_typeck/src/check/check.rs
@@ -371,14 +371,12 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
         let param_env = tcx.param_env(item_def_id);
         for field in fields {
             let field_ty = field.ty(tcx, substs);
-            let (field_span, ty_span) =
-                // We are currently checking the type this field came from, so it must be local.
-                if let Node::Field(field) = tcx.hir().get_if_local(field.did).unwrap() {
-                    (field.span, field.ty.span)
-                } else {
-                    unreachable!("mir field has to correspond to hir field");
-                };
             if field_ty.needs_drop(tcx, param_env) {
+                let (field_span, ty_span) = match tcx.hir().get_if_local(field.did) {
+                    // We are currently checking the type this field came from, so it must be local.
+                    Some(Node::Field(field)) => (field.span, field.ty.span),
+                    _ => unreachable!("mir field has to correspond to hir field"),
+                };
                 struct_span_err!(
                     tcx.sess,
                     field_span,
@@ -387,7 +385,10 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
                 )
                 .multipart_suggestion_verbose(
                     "wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped",
-                    vec![(ty_span, format!("std::mem::ManuallyDrop<{}>", field_ty))],
+                    vec![
+                        (ty_span.shrink_to_lo(), format!("std::mem::ManuallyDrop<")),
+                        (ty_span.shrink_to_hi(), ">".into()),
+                    ],
                     Applicability::MaybeIncorrect,
                 )
                 .emit();