Skip to content

Commit 6aaa606

Browse files
committed
Rollup merge of rust-lang#30774 - nagisa:mir-fix-constval-adts, r=arielb1
Fixes rust-lang#30772 We used to have a untested special case which didn’t really work anyway, because of lacking casts. This PR removes the case in question.
2 parents 19820c4 + ea52d9e commit 6aaa606

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/librustc_trans/trans/mir/constant.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ use middle::ty::{Ty, TypeFoldable};
1515
use rustc::middle::const_eval::ConstVal;
1616
use rustc::mir::repr as mir;
1717
use trans::common::{self, Block, C_bool, C_bytes, C_floating_f64, C_integral, C_str_slice};
18-
use trans::consts::{self, TrueConst};
19-
use trans::{type_of, expr};
20-
18+
use trans::consts;
19+
use trans::expr;
20+
use trans::type_of;
2121

2222
use super::operand::{OperandRef, OperandValue};
2323
use super::MirContext;
2424

25+
2526
impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
2627
pub fn trans_constval(&mut self,
2728
bcx: Block<'bcx, 'tcx>,
@@ -66,13 +67,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
6667
ConstVal::Uint(v) => C_integral(llty, v, false),
6768
ConstVal::Str(ref v) => C_str_slice(ccx, v.clone()),
6869
ConstVal::ByteStr(ref v) => consts::addr_of(ccx, C_bytes(ccx, v), 1, "byte_str"),
69-
ConstVal::Struct(id) | ConstVal::Tuple(id) => {
70-
let expr = bcx.tcx().map.expect_expr(id);
71-
match consts::const_expr(ccx, expr, param_substs, None, TrueConst::Yes) {
72-
Ok((val, _)) => val,
73-
Err(e) => panic!("const eval failure: {}", e.description()),
74-
}
75-
},
70+
ConstVal::Struct(id) | ConstVal::Tuple(id) |
7671
ConstVal::Array(id, _) | ConstVal::Repeat(id, _) => {
7772
let expr = bcx.tcx().map.expect_expr(id);
7873
expr::trans(bcx, expr).datum.val
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2016 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+
#![feature(rustc_attrs)]
11+
12+
#[derive(PartialEq, Debug)]
13+
struct Point {
14+
_x: i32,
15+
_y: i32,
16+
}
17+
const STRUCT: Point = Point { _x: 42, _y: 42 };
18+
const TUPLE1: (i32, i32) = (42, 42);
19+
const TUPLE2: (&'static str, &'static str) = ("hello","world");
20+
21+
#[rustc_mir]
22+
fn mir() -> (Point, (i32, i32), (&'static str, &'static str)){
23+
let struct1 = STRUCT;
24+
let tuple1 = TUPLE1;
25+
let tuple2 = TUPLE2;
26+
(struct1, tuple1, tuple2)
27+
}
28+
29+
fn main(){
30+
assert_eq!(mir(), (STRUCT, TUPLE1, TUPLE2));
31+
}
32+

0 commit comments

Comments
 (0)