diff options
| author | bors <bors@rust-lang.org> | 2015-12-21 00:39:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-12-21 00:39:24 +0000 |
| commit | 2b8e96dad2d30d1ece97a382e63dd845b354890e (patch) | |
| tree | df69d6a59b8340468e2f830af8c665f47c52c884 /src | |
| parent | 3d150397a220d14e3236367587c6cdfdcaacab57 (diff) | |
| parent | 0f860c2977323c62da260c6f290b7edd48dc4d4a (diff) | |
Auto merge of #30482 - luqmana:const-fat-ptr, r=dotdash
Fixes #30479.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_trans/trans/mir/constant.rs | 5 | ||||
| -rw-r--r-- | src/test/run-pass/mir_fat_ptr.rs | 7 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/librustc_trans/trans/mir/constant.rs b/src/librustc_trans/trans/mir/constant.rs index 38fab1dbf07..70a56990efd 100644 --- a/src/librustc_trans/trans/mir/constant.rs +++ b/src/librustc_trans/trans/mir/constant.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use back::abi; use middle::ty::{Ty, HasTypeFlags}; use rustc::middle::const_eval::ConstVal; use rustc::mir::repr as mir; @@ -29,6 +30,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { let val = consts::trans_constval(bcx, cv, ty, bcx.fcx.param_substs); let val = if common::type_is_immediate(ccx, ty) { OperandValue::Immediate(val) + } else if common::type_is_fat_ptr(bcx.tcx(), ty) { + let data = common::const_get_elt(ccx, val, &[abi::FAT_PTR_ADDR as u32]); + let extra = common::const_get_elt(ccx, val, &[abi::FAT_PTR_EXTRA as u32]); + OperandValue::FatPtr(data, extra) } else { OperandValue::Ref(val) }; diff --git a/src/test/run-pass/mir_fat_ptr.rs b/src/test/run-pass/mir_fat_ptr.rs index 1916e608a8c..9a4267bec92 100644 --- a/src/test/run-pass/mir_fat_ptr.rs +++ b/src/test/run-pass/mir_fat_ptr.rs @@ -49,6 +49,11 @@ fn fat_ptr_store_to<'a>(a: &'a [u8], b: &mut &'a [u8]) { *b = a; } +#[rustc_mir] +fn fat_ptr_constant() -> &'static str { + "HELLO" +} + fn main() { let a = Wrapper(4, [7,6,5]); @@ -60,4 +65,6 @@ fn main() { let mut target : &[u8] = &[42]; fat_ptr_store_to(p, &mut target); assert_eq!(target, &a.1); + + assert_eq!(fat_ptr_constant(), "HELLO"); } |
