use crate::llvm::{self, SetUnnamedAddr, True};
use crate::debuginfo;
-use crate::monomorphize::MonoItem;
use crate::common::CodegenCx;
-use crate::monomorphize::Instance;
use crate::base;
use crate::type_::Type;
use crate::type_of::LayoutLlvmExt;
use rustc::hir::def_id::DefId;
use rustc::mir::interpret::{ConstValue, Allocation, read_target_uint,
Pointer, ErrorHandled, GlobalId};
+use rustc::mir::mono::MonoItem;
use rustc::hir::Node;
use syntax_pos::Span;
use rustc_target::abi::HasDataLayout;
use syntax::symbol::sym;
use syntax_pos::symbol::LocalInternedString;
-use rustc::ty::{self, Ty};
+use rustc::ty::{self, Ty, Instance};
use rustc_codegen_ssa::traits::*;
use rustc::ty::layout::{self, Size, Align, LayoutOf};
attrs: &CodegenFnAttrs,
ty: Ty<'tcx>,
sym: LocalInternedString,
- span: Option<Span>
+ span: Span
) -> &'ll Value {
let llty = cx.layout_of(ty).llvm_type(cx);
if let Some(linkage) = attrs.linkage {
let llty2 = if let ty::RawPtr(ref mt) = ty.sty {
cx.layout_of(mt.ty).llvm_type(cx)
} else {
- if let Some(span) = span {
- cx.sess().span_fatal(span, "must have type `*const T` or `*mut T`")
- } else {
- bug!("must have type `*const T` or `*mut T`")
- }
+ cx.sess().span_fatal(
+ span, "must have type `*const T` or `*mut T` due to `#[linkage]` attribute")
};
unsafe {
// Declare a symbol `foo` with the desired linkage.
let mut real_name = "_rust_extern_with_linkage_".to_string();
real_name.push_str(&sym);
let g2 = cx.define_global(&real_name, llty).unwrap_or_else(||{
- if let Some(span) = span {
- cx.sess().span_fatal(
- span,
- &format!("symbol `{}` is already defined", &sym)
- )
- } else {
- bug!("symbol `{}` is already defined", &sym)
- }
+ cx.sess().span_fatal(span, &format!("symbol `{}` is already defined", &sym))
});
llvm::LLVMRustSetLinkage(g2, llvm::Linkage::InternalLinkage);
llvm::LLVMSetInitializer(g2, g1);
ref attrs, span, node: hir::ForeignItemKind::Static(..), ..
}) => {
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
- (check_and_apply_linkage(&self, &fn_attrs, ty, sym, Some(span)), attrs)
+ (check_and_apply_linkage(&self, &fn_attrs, ty, sym, span), attrs)
}
item => bug!("get_static: expected static, found {:?}", item)
debug!("get_static: sym={} item_attr={:?}", sym, self.tcx.item_attrs(def_id));
let attrs = self.tcx.codegen_fn_attrs(def_id);
- let g = check_and_apply_linkage(&self, &attrs, ty, sym, None);
+ let span = self.tcx.def_span(def_id);
+ let g = check_and_apply_linkage(&self, &attrs, ty, sym, span);
// Thread-local statics in some other crate need to *always* be linked
// against in a thread-local fashion, so we need to be sure to apply the