File tree 2 files changed +42
-7
lines changed
2 files changed +42
-7
lines changed Original file line number Diff line number Diff line change @@ -359,14 +359,12 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
359
359
/// Set the discriminant for a new value of the given case of the given
360
360
/// representation.
361
361
pub fn trans_set_discr ( & self , bcx : & Builder < ' a , ' tcx > , variant_index : usize ) {
362
- match self . layout . variants {
362
+ if self . layout . for_variant ( bcx. ccx , variant_index) . abi == layout:: Abi :: Uninhabited {
363
+ return ;
364
+ }
365
+ match self . layout . variants {
363
366
layout:: Variants :: Single { index } => {
364
- if index != variant_index {
365
- // If the layout of an enum is `Single`, all
366
- // other variants are necessarily uninhabited.
367
- assert_eq ! ( self . layout. for_variant( bcx. ccx, variant_index) . abi,
368
- layout:: Abi :: Uninhabited ) ;
369
- }
367
+ assert_eq ! ( index, variant_index) ;
370
368
}
371
369
layout:: Variants :: Tagged { .. } => {
372
370
let ptr = self . project_field ( bcx, 0 ) ;
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // compile-flags:--test -O
12
+
13
+ #[ test]
14
+ #[ should_panic( expected = "creating inhabited type" ) ]
15
+ fn test ( ) {
16
+ FontLanguageOverride :: system_font ( SystemFont :: new ( ) ) ;
17
+ }
18
+
19
+ pub enum FontLanguageOverride {
20
+ Normal ,
21
+ Override ( & ' static str ) ,
22
+ System ( SystemFont )
23
+ }
24
+
25
+ pub enum SystemFont { }
26
+
27
+ impl FontLanguageOverride {
28
+ fn system_font ( f : SystemFont ) -> Self {
29
+ FontLanguageOverride :: System ( f)
30
+ }
31
+ }
32
+
33
+ impl SystemFont {
34
+ fn new ( ) -> Self {
35
+ panic ! ( "creating inhabited type" )
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments