Skip to content

Commit f1342ff

Browse files
committed
Simplify trans/exprs.rs DefStatic considerably
1 parent 21deb18 commit f1342ff

File tree

2 files changed

+2
-23
lines changed

2 files changed

+2
-23
lines changed

src/librustc_trans/trans/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,6 @@ pub fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
12211221
if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) {
12221222
base::get_item_val(ccx, node_id)
12231223
} else {
1224-
base::trans_external_path(ccx, did, ty)
1224+
base::get_extern_const(ccx, did, ty)
12251225
}
12261226
}

src/librustc_trans/trans/expr.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -941,29 +941,8 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
941941
DatumBlock::new(bcx, datum.to_expr_datum())
942942
}
943943
def::DefStatic(did, _) => {
944-
// There are two things that may happen here:
945-
// 1) If the static item is defined in this crate, it will be
946-
// translated using `get_item_val`, and we return a pointer to
947-
// the result.
948-
// 2) If the static item is defined in another crate then we add
949-
// (or reuse) a declaration of an external global, and return a
950-
// pointer to that.
951944
let const_ty = expr_ty(bcx, ref_expr);
952-
953-
// For external constants, we don't inline.
954-
let val = if let Some(node_id) = bcx.tcx().map.as_local_node_id(did) {
955-
// Case 1.
956-
957-
// The LLVM global has the type of its initializer,
958-
// which may not be equal to the enum's type for
959-
// non-C-like enums.
960-
let val = base::get_item_val(bcx.ccx(), node_id);
961-
let pty = type_of::type_of(bcx.ccx(), const_ty).ptr_to();
962-
PointerCast(bcx, val, pty)
963-
} else {
964-
// Case 2.
965-
base::get_extern_const(bcx.ccx(), did, const_ty)
966-
};
945+
let val = get_static_val(bcx.ccx(), did, const_ty);
967946
let lval = Lvalue::new("expr::trans_def");
968947
DatumBlock::new(bcx, Datum::new(val, const_ty, LvalueExpr(lval)))
969948
}

0 commit comments

Comments
 (0)