Skip to content

Commit 423dd84

Browse files
committed
auto merge of #11441 : jld/rust/enum-nullable-const-null-with-fields, r=alexcrichton
That is, if you have an enum type that is subject to the nullable pointer optimization, but the null variant has a nonzero number of fields, and you declare a static whose value is of that variant, then that used to be an ICE but this change fixes it.
2 parents 72a5252 + 5487f15 commit 423dd84

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc/middle/trans/adt.rs

-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr,
730730
if discr == nndiscr {
731731
C_struct(build_const_struct(ccx, nonnull, vals), false)
732732
} else {
733-
assert_eq!(vals.len(), 0);
734733
let vals = nonnull.fields.iter().enumerate().map(|(i, &ty)| {
735734
let llty = type_of::sizing_type_of(ccx, ty);
736735
if i == ptrfield { C_null(llty) } else { C_undef(llty) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 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+
use std::result::{Result,Ok};
12+
static C: Result<(), ~int> = Ok(());
13+
14+
// This is because of yet another bad assertion (ICE) about the null side of a nullable enum.
15+
// So we won't actually compile if the bug is present, but we check the value in main anyway.
16+
17+
pub fn main() {
18+
assert!(C.is_ok());
19+
}

0 commit comments

Comments
 (0)