Skip to content

Commit 253dbcb

Browse files
committed
auto merge of #12703 : jld/rust/issue-8506, r=alexcrichton
Closes #8506.
2 parents 67c5d79 + d908302 commit 253dbcb

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/librustc/middle/trans/adt.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -749,14 +749,15 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr,
749749
let contents = build_const_struct(ccx, st, vals);
750750
C_struct(contents, st.packed)
751751
}
752-
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, .. } => {
752+
NullablePointer{ nonnull: ref nonnull, nndiscr, .. } => {
753753
if discr == nndiscr {
754754
C_struct(build_const_struct(ccx, nonnull, vals), false)
755755
} else {
756-
let vals = nonnull.fields.iter().enumerate().map(|(i, &ty)| {
757-
let llty = type_of::sizing_type_of(ccx, ty);
758-
if i == ptrfield { C_null(llty) } else { C_undef(llty) }
759-
}).collect::<~[ValueRef]>();
756+
let vals = nonnull.fields.map(|&ty| {
757+
// Always use null even if it's not the `ptrfield`th
758+
// field; see #8506.
759+
C_null(type_of::sizing_type_of(ccx, ty))
760+
});
760761
C_struct(build_const_struct(ccx, nonnull, vals), false)
761762
}
762763
}
@@ -791,14 +792,8 @@ fn build_const_struct(ccx: &CrateContext, st: &Struct, vals: &[ValueRef])
791792
cfields.push(padding(target_offset - offset));
792793
offset = target_offset;
793794
}
794-
let val = if is_undef(vals[i]) {
795-
let wrapped = C_struct([vals[i]], false);
796-
assert!(!is_undef(wrapped));
797-
wrapped
798-
} else {
799-
vals[i]
800-
};
801-
cfields.push(val);
795+
assert!(!is_undef(vals[i]));
796+
cfields.push(vals[i]);
802797
offset += machine::llsize_of_alloc(ccx, llty) as u64
803798
}
804799

src/test/run-pass/issue-8506.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013-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+
#[allow(dead_code)];
12+
13+
enum Either {
14+
One,
15+
Other(~str,~str)
16+
}
17+
18+
static one : Either = One;
19+
20+
pub fn main () { }

0 commit comments

Comments
 (0)