about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2015-11-11 00:19:37 +0200
committerSimonas Kazlauskas <git@kazlauskas.me>2015-11-11 00:42:09 +0200
commitf1342ffb3ca3f5641b55ecdc6481f5cd80f338d6 (patch)
tree86830a9edb97913585f74f93cd25fa1d8b9cdcfb
parent21deb18bfd2d84c8230b906f455007957013766e (diff)
Simplify trans/exprs.rs DefStatic considerably
-rw-r--r--src/librustc_trans/trans/common.rs2
-rw-r--r--src/librustc_trans/trans/expr.rs23
2 files changed, 2 insertions, 23 deletions
diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs
index 7dda864d1ed..ac3e3beeac8 100644
--- a/src/librustc_trans/trans/common.rs
+++ b/src/librustc_trans/trans/common.rs
@@ -1221,6 +1221,6 @@ pub fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) {
         base::get_item_val(ccx, node_id)
     } else {
-        base::trans_external_path(ccx, did, ty)
+        base::get_extern_const(ccx, did, ty)
     }
 }
diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs
index 7648587e352..f408bb595a2 100644
--- a/src/librustc_trans/trans/expr.rs
+++ b/src/librustc_trans/trans/expr.rs
@@ -941,29 +941,8 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
             DatumBlock::new(bcx, datum.to_expr_datum())
         }
         def::DefStatic(did, _) => {
-            // There are two things that may happen here:
-            //  1) If the static item is defined in this crate, it will be
-            //     translated using `get_item_val`, and we return a pointer to
-            //     the result.
-            //  2) If the static item is defined in another crate then we add
-            //     (or reuse) a declaration of an external global, and return a
-            //     pointer to that.
             let const_ty = expr_ty(bcx, ref_expr);
-
-            // For external constants, we don't inline.
-            let val = if let Some(node_id) = bcx.tcx().map.as_local_node_id(did) {
-                // Case 1.
-
-                // The LLVM global has the type of its initializer,
-                // which may not be equal to the enum's type for
-                // non-C-like enums.
-                let val = base::get_item_val(bcx.ccx(), node_id);
-                let pty = type_of::type_of(bcx.ccx(), const_ty).ptr_to();
-                PointerCast(bcx, val, pty)
-            } else {
-                // Case 2.
-                base::get_extern_const(bcx.ccx(), did, const_ty)
-            };
+            let val = get_static_val(bcx.ccx(), did, const_ty);
             let lval = Lvalue::new("expr::trans_def");
             DatumBlock::new(bcx, Datum::new(val, const_ty, LvalueExpr(lval)))
         }