about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2019-10-21 09:08:05 +0200
committerOliver Scherer <github35764891676564198441@oli-obk.de>2019-10-21 09:08:05 +0200
commit0653694fdc46a2bca119b9790d1dfd62e1b4901e (patch)
treecc44a50cd95d85967e2d2393380b3c9d18094703
parentbb5a652361bb416e38fa4f41784dd5d08b232f59 (diff)
downloadrust-0653694fdc46a2bca119b9790d1dfd62e1b4901e.tar.gz
rust-0653694fdc46a2bca119b9790d1dfd62e1b4901e.zip
Don't silently do nothing on mis_use of `check_union_fields`
-rw-r--r--src/librustc_typeck/check/mod.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 3e0527393cd..d5182d69c3e 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -1393,7 +1393,7 @@ fn check_union(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) {
 
 /// When the `#![feature(untagged_unions)]` gate is active,
 /// check that the fields of the `union` does not contain fields that need dropping.
-fn check_union_fields(tcx: TyCtxt<'_>, _: Span, item_def_id: DefId) -> bool {
+fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: DefId) -> bool {
     // Without the feature we check that all fields are `Copy` in our stability checking
     // infrastructure.
     if !tcx.features().untagged_unions {
@@ -1401,23 +1401,24 @@ fn check_union_fields(tcx: TyCtxt<'_>, _: Span, item_def_id: DefId) -> bool {
     }
     let item_type = tcx.type_of(item_def_id);
     if let ty::Adt(def, substs) = item_type.kind {
-        if def.is_union() {
-            let fields = &def.non_enum_variant().fields;
-            for field in fields {
-                let field_ty = field.ty(tcx, substs);
-                // We are currently checking the type this field came from, so it must be local.
-                let field_span = tcx.hir().span_if_local(field.did).unwrap();
-                let param_env = tcx.param_env(field.did);
-                if field_ty.needs_drop(tcx, param_env) {
-                    struct_span_err!(tcx.sess, field_span, E0740,
-                                     "unions may not contain fields that need dropping")
-                                .span_note(field_span,
-                                           "`std::mem::ManuallyDrop` can be used to wrap the type")
-                                .emit();
-                    return false;
-                }
+        assert!(def.is_union());
+        let fields = &def.non_enum_variant().fields;
+        for field in fields {
+            let field_ty = field.ty(tcx, substs);
+            // We are currently checking the type this field came from, so it must be local.
+            let field_span = tcx.hir().span_if_local(field.did).unwrap();
+            let param_env = tcx.param_env(field.did);
+            if field_ty.needs_drop(tcx, param_env) {
+                struct_span_err!(tcx.sess, field_span, E0740,
+                                    "unions may not contain fields that need dropping")
+                            .span_note(field_span,
+                                        "`std::mem::ManuallyDrop` can be used to wrap the type")
+                            .emit();
+                return false;
             }
         }
+    } else {
+        span_bug!(span, "unions must be ty::Adt, but got {:?}", item_type.kind);
     }
     return true;
 }