Skip to content

Commit 2b8e96d

Browse files
committed
Auto merge of #30482 - luqmana:const-fat-ptr, r=dotdash
Fixes #30479.
2 parents 3d15039 + 0f860c2 commit 2b8e96d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/librustc_trans/trans/mir/constant.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use back::abi;
1112
use middle::ty::{Ty, HasTypeFlags};
1213
use rustc::middle::const_eval::ConstVal;
1314
use rustc::mir::repr as mir;
@@ -29,6 +30,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
2930
let val = consts::trans_constval(bcx, cv, ty, bcx.fcx.param_substs);
3031
let val = if common::type_is_immediate(ccx, ty) {
3132
OperandValue::Immediate(val)
33+
} else if common::type_is_fat_ptr(bcx.tcx(), ty) {
34+
let data = common::const_get_elt(ccx, val, &[abi::FAT_PTR_ADDR as u32]);
35+
let extra = common::const_get_elt(ccx, val, &[abi::FAT_PTR_EXTRA as u32]);
36+
OperandValue::FatPtr(data, extra)
3237
} else {
3338
OperandValue::Ref(val)
3439
};

src/test/run-pass/mir_fat_ptr.rs

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ fn fat_ptr_store_to<'a>(a: &'a [u8], b: &mut &'a [u8]) {
4949
*b = a;
5050
}
5151

52+
#[rustc_mir]
53+
fn fat_ptr_constant() -> &'static str {
54+
"HELLO"
55+
}
56+
5257
fn main() {
5358
let a = Wrapper(4, [7,6,5]);
5459

@@ -60,4 +65,6 @@ fn main() {
6065
let mut target : &[u8] = &[42];
6166
fat_ptr_store_to(p, &mut target);
6267
assert_eq!(target, &a.1);
68+
69+
assert_eq!(fat_ptr_constant(), "HELLO");
6370
}

0 commit comments

Comments
 (0)