Skip to content

Commit 21deb18

Browse files
committed
[MIR trans] Translate statics
Fixes #29578
1 parent 05b66b8 commit 21deb18

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/librustc_trans/trans/common.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,3 +1214,13 @@ pub fn shift_mask_val<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
12141214
}
12151215
}
12161216

1217+
pub fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1218+
did: DefId,
1219+
ty: Ty<'tcx>)
1220+
-> ValueRef {
1221+
if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) {
1222+
base::get_item_val(ccx, node_id)
1223+
} else {
1224+
base::trans_external_path(ccx, did, ty)
1225+
}
1226+
}

src/librustc_trans/trans/consts.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use middle::const_eval::eval_const_expr_partial;
2929
use middle::def_id::DefId;
3030
use trans::{adt, closure, debuginfo, expr, inline, machine};
3131
use trans::base::{self, push_ctxt};
32+
use trans::common::{self, type_is_sized, ExprOrMethodCall, node_id_substs, C_nil, const_get_elt};
3233
use trans::common::{CrateContext, C_integral, C_floating, C_bool, C_str_slice, C_bytes, val_ty};
33-
use trans::common::{type_is_sized, ExprOrMethodCall, node_id_substs, C_nil, const_get_elt};
3434
use trans::common::{C_struct, C_undef, const_to_opt_int, const_to_opt_uint, VariantInfo, C_uint};
3535
use trans::common::{type_is_fat_ptr, Field, C_vector, C_array, C_null, ExprId, MethodCallKey};
3636
use trans::declare;
@@ -795,7 +795,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
795795
}
796796
let opt_def = cx.tcx().def_map.borrow().get(&cur.id).map(|d| d.full_def());
797797
if let Some(def::DefStatic(def_id, _)) = opt_def {
798-
get_static_val(cx, def_id, ety)
798+
common::get_static_val(cx, def_id, ety)
799799
} else {
800800
// If this isn't the address of a static, then keep going through
801801
// normal constant evaluation.
@@ -1075,15 +1075,3 @@ pub fn trans_static(ccx: &CrateContext,
10751075
Ok(g)
10761076
}
10771077
}
1078-
1079-
1080-
fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1081-
did: DefId,
1082-
ty: Ty<'tcx>)
1083-
-> ValueRef {
1084-
if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) {
1085-
base::get_item_val(ccx, node_id)
1086-
} else {
1087-
base::trans_external_path(ccx, did, ty)
1088-
}
1089-
}

src/librustc_trans/trans/mir/lvalue.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
6565
tcx.sess.bug(&format!("using operand temp {:?} as lvalue", lvalue)),
6666
},
6767
mir::Lvalue::Arg(index) => self.args[index as usize],
68-
mir::Lvalue::Static(_def_id) => unimplemented!(),
68+
mir::Lvalue::Static(def_id) => {
69+
let const_ty = self.mir.lvalue_ty(tcx, lvalue);
70+
LvalueRef::new(common::get_static_val(ccx, def_id, const_ty.to_ty(tcx)), const_ty)
71+
},
6972
mir::Lvalue::ReturnPointer => {
7073
let return_ty = bcx.monomorphize(&self.mir.return_ty);
7174
let llval = fcx.get_ret_slot(bcx, return_ty, "return");

0 commit comments

Comments
 (0)