]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/mono_item.rs
Auto merge of #68474 - tmandry:rollup-6gmbet6, r=tmandry
[rust.git] / src / librustc_codegen_llvm / mono_item.rs
index 9f6bdd2390082a0325ca3d83b85d4b1a40ce43aa..97393e69e995fcb52830bc6d1ec4ceffbb27cd20 100644 (file)
@@ -4,28 +4,32 @@
 use crate::context::CodegenCx;
 use crate::llvm;
 use crate::type_of::LayoutLlvmExt;
-use rustc::hir::def_id::{DefId, LOCAL_CRATE};
+use log::debug;
 use rustc::mir::mono::{Linkage, Visibility};
-use rustc::ty::{TypeFoldable, Instance};
 use rustc::ty::layout::{FnAbiExt, LayoutOf};
+use rustc::ty::{Instance, TypeFoldable};
 use rustc_codegen_ssa::traits::*;
-use log::debug;
+use rustc_hir::def_id::{DefId, LOCAL_CRATE};
 
 pub use rustc::mir::mono::MonoItem;
 
 impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> {
-    fn predefine_static(&self,
-                                  def_id: DefId,
-                                  linkage: Linkage,
-                                  visibility: Visibility,
-                                  symbol_name: &str) {
+    fn predefine_static(
+        &self,
+        def_id: DefId,
+        linkage: Linkage,
+        visibility: Visibility,
+        symbol_name: &str,
+    ) {
         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 = self.define_global(symbol_name, llty).unwrap_or_else(|| {
-            self.sess().span_fatal(self.tcx.def_span(def_id),
-                &format!("symbol `{}` is already defined", symbol_name))
+            self.sess().span_fatal(
+                self.tcx.def_span(def_id),
+                &format!("symbol `{}` is already defined", symbol_name),
+            )
         });
 
         unsafe {
@@ -36,21 +40,21 @@ fn predefine_static(&self,
         self.instances.borrow_mut().insert(instance, g);
     }
 
-    fn predefine_fn(&self,
-                    instance: Instance<'tcx>,
-                    linkage: Linkage,
-                    visibility: Visibility,
-                    symbol_name: &str) {
-        assert!(!instance.substs.needs_infer() &&
-                !instance.substs.has_param_types());
+    fn predefine_fn(
+        &self,
+        instance: Instance<'tcx>,
+        linkage: Linkage,
+        visibility: Visibility,
+        symbol_name: &str,
+    ) {
+        assert!(!instance.substs.needs_infer() && !instance.substs.has_param_types());
 
         let fn_abi = FnAbi::of_instance(self, instance, &[]);
         let lldecl = self.declare_fn(symbol_name, &fn_abi);
         unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
         let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
         base::set_link_section(lldecl, &attrs);
-        if linkage == Linkage::LinkOnceODR ||
-            linkage == Linkage::WeakODR {
+        if linkage == Linkage::LinkOnceODR || linkage == Linkage::WeakODR {
             llvm::SetUniqueComdat(self.llmod, lldecl);
         }
 
@@ -58,8 +62,10 @@ fn predefine_fn(&self,
         // compiler-rt, then we want to implicitly compile everything with hidden
         // visibility as we're going to link this object all over the place but
         // don't want the symbols to get exported.
-        if linkage != Linkage::Internal && linkage != Linkage::Private &&
-           self.tcx.is_compiler_builtins(LOCAL_CRATE) {
+        if linkage != Linkage::Internal
+            && linkage != Linkage::Private
+            && self.tcx.is_compiler_builtins(LOCAL_CRATE)
+        {
             unsafe {
                 llvm::LLVMRustSetVisibility(lldecl, llvm::Visibility::Hidden);
             }