]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/consts.rs
Change const eval to return `ConstValue`, instead of `Const` as the type inside it...
[rust.git] / src / librustc_codegen_llvm / consts.rs
index 4b4fbd0e1ad53a8f2f2227f2e20d721d5c4826d7..09a84aff16811a80f14db9fd288fcbdfadee73ac 100644 (file)
@@ -7,8 +7,6 @@
 use crate::value::Value;
 use libc::c_uint;
 use log::debug;
-use rustc::hir::def_id::DefId;
-use rustc::hir::{self, Node};
 use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
 use rustc::mir::interpret::{read_target_uint, Allocation, ConstValue, ErrorHandled, Pointer};
 use rustc::mir::mono::MonoItem;
@@ -16,6 +14,9 @@
 use rustc::ty::{self, Instance, Ty};
 use rustc::{bug, span_bug};
 use rustc_codegen_ssa::traits::*;
+use rustc_hir as hir;
+use rustc_hir::def_id::DefId;
+use rustc_hir::Node;
 use rustc_span::symbol::{sym, Symbol};
 use rustc_span::Span;
 use rustc_target::abi::HasDataLayout;
@@ -77,11 +78,9 @@ pub fn codegen_static_initializer(
     cx: &CodegenCx<'ll, 'tcx>,
     def_id: DefId,
 ) -> Result<(&'ll Value, &'tcx Allocation), ErrorHandled> {
-    let static_ = cx.tcx.const_eval_poly(def_id)?;
-
-    let alloc = match static_.val {
-        ty::ConstKind::Value(ConstValue::ByRef { alloc, offset }) if offset.bytes() == 0 => alloc,
-        _ => bug!("static const eval returned {:#?}", static_),
+    let alloc = match cx.tcx.const_eval_poly(def_id)? {
+        ConstValue::ByRef { alloc, offset } if offset.bytes() == 0 => alloc,
+        val => bug!("static const eval returned {:#?}", val),
     };
     Ok((const_alloc_to_llvm(cx, alloc), alloc))
 }
@@ -204,7 +203,7 @@ impl CodegenCx<'ll, 'tcx> {
             def_id
         );
 
-        let ty = instance.ty(self.tcx);
+        let ty = instance.monomorphic_ty(self.tcx);
         let sym = self.tcx.symbol_name(instance).name;
 
         debug!("get_static: sym={} instance={:?}", sym, instance);
@@ -361,7 +360,7 @@ fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
             };
 
             let instance = Instance::mono(self.tcx, def_id);
-            let ty = instance.ty(self.tcx);
+            let ty = instance.monomorphic_ty(self.tcx);
             let llty = self.layout_of(ty).llvm_type(self);
             let g = if val_llty == llty {
                 g