about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2016-06-07 02:21:58 +0300
committerEduard Burtescu <edy.burt@gmail.com>2016-06-07 02:21:58 +0300
commit11e31091a9e7e3604d79d9e820067120945c538d (patch)
tree05ab0264eb5165808ce4a5cff1ff1bfc702c352a
parentb6d9f8387aaa9ccd9ba0b379b60c402561fad970 (diff)
downloadrust-11e31091a9e7e3604d79d9e820067120945c538d.tar.gz
rust-11e31091a9e7e3604d79d9e820067120945c538d.zip
trans: don't forget to cast Pair constants of the wrong type.
-rw-r--r--src/librustc_trans/mir/constant.rs4
-rw-r--r--src/test/run-pass/mir_constval_adts.rs14
2 files changed, 10 insertions, 8 deletions
diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs
index d352a8241ac..53471887073 100644
--- a/src/librustc_trans/mir/constant.rs
+++ b/src/librustc_trans/mir/constant.rs
@@ -122,10 +122,10 @@ impl<'tcx> Const<'tcx> {
         let llty = type_of::immediate_type_of(ccx, self.ty);
         let llvalty = val_ty(self.llval);
 
-        let val = if common::type_is_imm_pair(ccx, self.ty) {
+        let val = if llty == llvalty && common::type_is_imm_pair(ccx, self.ty) {
             let (a, b) = self.get_pair();
             OperandValue::Pair(a, b)
-        } else if common::type_is_immediate(ccx, self.ty) && llty == llvalty {
+        } else if llty == llvalty && common::type_is_immediate(ccx, self.ty) {
             // If the types match, we can use the value directly.
             OperandValue::Immediate(self.llval)
         } else {
diff --git a/src/test/run-pass/mir_constval_adts.rs b/src/test/run-pass/mir_constval_adts.rs
index 4e9c0bce646..0ce9e88ef3d 100644
--- a/src/test/run-pass/mir_constval_adts.rs
+++ b/src/test/run-pass/mir_constval_adts.rs
@@ -15,21 +15,23 @@ struct Point {
     _y: i32,
 }
 
+#[derive(PartialEq, Eq, Debug)]
+struct Newtype<T>(T);
+
 const STRUCT: Point = Point { _x: 42, _y: 42 };
 const TUPLE1: (i32, i32) = (42, 42);
 const TUPLE2: (&'static str, &'static str) = ("hello","world");
+const PAIR_NEWTYPE: (Newtype<i32>, Newtype<i32>) = (Newtype(42), Newtype(42));
 
 #[rustc_mir]
-fn mir() -> (Point, (i32, i32), (&'static str, &'static str)){
+fn mir() -> (Point, (i32, i32), (&'static str, &'static str), (Newtype<i32>, Newtype<i32>)) {
     let struct1 = STRUCT;
     let tuple1 = TUPLE1;
     let tuple2 = TUPLE2;
-    (struct1, tuple1, tuple2)
+    let pair_newtype = PAIR_NEWTYPE;
+    (struct1, tuple1, tuple2, pair_newtype)
 }
 
-#[derive(PartialEq, Eq, Debug)]
-struct Newtype<T>(T);
-
 const NEWTYPE: Newtype<&'static str> = Newtype("foobar");
 
 #[rustc_mir]
@@ -39,7 +41,7 @@ fn test_promoted_newtype_str_ref() {
 }
 
 fn main(){
-    assert_eq!(mir(), (STRUCT, TUPLE1, TUPLE2));
+    assert_eq!(mir(), (STRUCT, TUPLE1, TUPLE2, PAIR_NEWTYPE));
     test_promoted_newtype_str_ref();
 }