Skip to content

Commit 11e3109

Browse files
committed
trans: don't forget to cast Pair constants of the wrong type.
1 parent b6d9f83 commit 11e3109

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/librustc_trans/mir/constant.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ impl<'tcx> Const<'tcx> {
122122
let llty = type_of::immediate_type_of(ccx, self.ty);
123123
let llvalty = val_ty(self.llval);
124124

125-
let val = if common::type_is_imm_pair(ccx, self.ty) {
125+
let val = if llty == llvalty && common::type_is_imm_pair(ccx, self.ty) {
126126
let (a, b) = self.get_pair();
127127
OperandValue::Pair(a, b)
128-
} else if common::type_is_immediate(ccx, self.ty) && llty == llvalty {
128+
} else if llty == llvalty && common::type_is_immediate(ccx, self.ty) {
129129
// If the types match, we can use the value directly.
130130
OperandValue::Immediate(self.llval)
131131
} else {

src/test/run-pass/mir_constval_adts.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ struct Point {
1515
_y: i32,
1616
}
1717

18+
#[derive(PartialEq, Eq, Debug)]
19+
struct Newtype<T>(T);
20+
1821
const STRUCT: Point = Point { _x: 42, _y: 42 };
1922
const TUPLE1: (i32, i32) = (42, 42);
2023
const TUPLE2: (&'static str, &'static str) = ("hello","world");
24+
const PAIR_NEWTYPE: (Newtype<i32>, Newtype<i32>) = (Newtype(42), Newtype(42));
2125

2226
#[rustc_mir]
23-
fn mir() -> (Point, (i32, i32), (&'static str, &'static str)){
27+
fn mir() -> (Point, (i32, i32), (&'static str, &'static str), (Newtype<i32>, Newtype<i32>)) {
2428
let struct1 = STRUCT;
2529
let tuple1 = TUPLE1;
2630
let tuple2 = TUPLE2;
27-
(struct1, tuple1, tuple2)
31+
let pair_newtype = PAIR_NEWTYPE;
32+
(struct1, tuple1, tuple2, pair_newtype)
2833
}
2934

30-
#[derive(PartialEq, Eq, Debug)]
31-
struct Newtype<T>(T);
32-
3335
const NEWTYPE: Newtype<&'static str> = Newtype("foobar");
3436

3537
#[rustc_mir]
@@ -39,7 +41,7 @@ fn test_promoted_newtype_str_ref() {
3941
}
4042

4143
fn main(){
42-
assert_eq!(mir(), (STRUCT, TUPLE1, TUPLE2));
44+
assert_eq!(mir(), (STRUCT, TUPLE1, TUPLE2, PAIR_NEWTYPE));
4345
test_promoted_newtype_str_ref();
4446
}
4547

0 commit comments

Comments
 (0)