about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <ariel.byd@gmail.com>2017-12-21 19:40:20 +0200
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2017-12-21 19:40:20 +0200
commit2348ab4fbcf93ecb9e372190b4b6ca46f15e1006 (patch)
treeb0928ed3f6b4820b29a61eaefed79001a4c9634e
parent3ab24df3bfa69e7922f878e4f661fcc979630920 (diff)
downloadrust-2348ab4fbcf93ecb9e372190b4b6ca46f15e1006.tar.gz
rust-2348ab4fbcf93ecb9e372190b4b6ca46f15e1006.zip
Revert "rustc_trans: don't write discriminants for uninhabited variants"
This reverts commit 4e28c6174b3fa2ec2031f913d35090392373ae70.
-rw-r--r--src/librustc_trans/mir/lvalue.rs12
-rw-r--r--src/test/run-pass/issue-46519.rs37
2 files changed, 7 insertions, 42 deletions
diff --git a/src/librustc_trans/mir/lvalue.rs b/src/librustc_trans/mir/lvalue.rs
index 91555f97b10..891d52045c2 100644
--- a/src/librustc_trans/mir/lvalue.rs
+++ b/src/librustc_trans/mir/lvalue.rs
@@ -359,12 +359,14 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
     /// Set the discriminant for a new value of the given case of the given
     /// representation.
     pub fn trans_set_discr(&self, bcx: &Builder<'a, 'tcx>, variant_index: usize) {
-            if self.layout.for_variant(bcx.ccx, variant_index).abi == layout::Abi::Uninhabited {
-                return;
-            }
-            match self.layout.variants {
+        match self.layout.variants {
             layout::Variants::Single { index } => {
-                assert_eq!(index, variant_index);
+                if index != variant_index {
+                    // If the layout of an enum is `Single`, all
+                    // other variants are necessarily uninhabited.
+                    assert_eq!(self.layout.for_variant(bcx.ccx, variant_index).abi,
+                               layout::Abi::Uninhabited);
+                }
             }
             layout::Variants::Tagged { .. } => {
                 let ptr = self.project_field(bcx, 0);
diff --git a/src/test/run-pass/issue-46519.rs b/src/test/run-pass/issue-46519.rs
deleted file mode 100644
index 878cae4e387..00000000000
--- a/src/test/run-pass/issue-46519.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// compile-flags:--test -O
-
-#[test]
-#[should_panic(expected = "creating inhabited type")]
-fn test() {
-    FontLanguageOverride::system_font(SystemFont::new());
-}
-
-pub enum FontLanguageOverride {
-    Normal,
-    Override(&'static str),
-    System(SystemFont)
-}
-
-pub enum SystemFont {}
-
-impl FontLanguageOverride {
-    fn system_font(f: SystemFont) -> Self {
-        FontLanguageOverride::System(f)
-    }
-}
-
-impl SystemFont {
-    fn new() -> Self {
-        panic!("creating inhabited type")
-    }
-}