parent
c78cc52afd
commit
fcebf3beab
2 changed files with 50 additions and 9 deletions
|
@ -688,9 +688,8 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
|
|||
let lldiscr = C_integral(Type::from_integer(ccx, d), discr.0 as u64, true);
|
||||
let mut vals_with_discr = vec![lldiscr];
|
||||
vals_with_discr.extend_from_slice(vals);
|
||||
let mut contents = build_const_struct(ccx, &variant,
|
||||
&vals_with_discr[..]);
|
||||
let needed_padding = l.size(dl).bytes() - variant.min_size.bytes();
|
||||
let mut contents = build_const_struct(ccx, &variant, &vals_with_discr[..]);
|
||||
let needed_padding = l.size(dl).bytes() - variant.stride().bytes();
|
||||
if needed_padding > 0 {
|
||||
contents.push(padding(ccx, needed_padding));
|
||||
}
|
||||
|
@ -703,8 +702,7 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
|
|||
}
|
||||
layout::Univariant { ref variant, .. } => {
|
||||
assert_eq!(discr, Disr(0));
|
||||
let contents = build_const_struct(ccx,
|
||||
&variant, vals);
|
||||
let contents = build_const_struct(ccx, &variant, vals);
|
||||
C_struct(ccx, &contents[..], variant.packed)
|
||||
}
|
||||
layout::Vector { .. } => {
|
||||
|
@ -721,8 +719,7 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
|
|||
}
|
||||
layout::StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
|
||||
if discr.0 == nndiscr {
|
||||
C_struct(ccx, &build_const_struct(ccx, &nonnull, vals),
|
||||
false)
|
||||
C_struct(ccx, &build_const_struct(ccx, &nonnull, vals), false)
|
||||
} else {
|
||||
let fields = compute_fields(ccx, t, nndiscr as usize, false);
|
||||
let vals = fields.iter().map(|&ty| {
|
||||
|
@ -730,8 +727,7 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
|
|||
// field; see #8506.
|
||||
C_null(type_of::sizing_type_of(ccx, ty))
|
||||
}).collect::<Vec<ValueRef>>();
|
||||
C_struct(ccx, &build_const_struct(ccx, &nonnull, &vals[..]),
|
||||
false)
|
||||
C_struct(ccx, &build_const_struct(ccx, &nonnull, &vals[..]), false)
|
||||
}
|
||||
}
|
||||
_ => bug!("trans_const: cannot handle type {} repreented as {:#?}", t, l)
|
||||
|
|
45
src/test/run-pass/issue-38002.rs
Normal file
45
src/test/run-pass/issue-38002.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// Check that constant ADTs are translated OK, part k of N.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
enum Bar {
|
||||
C
|
||||
}
|
||||
|
||||
enum Foo {
|
||||
A {},
|
||||
B {
|
||||
y: usize,
|
||||
z: Bar
|
||||
},
|
||||
}
|
||||
|
||||
const LIST: [(usize, Foo); 2] = [
|
||||
(51, Foo::B { y: 42, z: Bar::C }),
|
||||
(52, Foo::B { y: 45, z: Bar::C }),
|
||||
];
|
||||
|
||||
pub fn main() {
|
||||
match LIST {
|
||||
[
|
||||
(51, Foo::B { y: 42, z: Bar::C }),
|
||||
(52, Foo::B { y: 45, z: Bar::C })
|
||||
] => {}
|
||||
_ => {
|
||||
// I would want to print the enum here, but if
|
||||
// the discriminant is garbage this causes an
|
||||
// `unreachable` and silent process exit.
|
||||
panic!("trivial match failed")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue