diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2019-05-24 14:11:39 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2019-05-27 10:26:02 +0200 |
| commit | 64edaec6b35ea32e8dffbe27ff123c4a090869a8 (patch) | |
| tree | 3b796f3eb53e9f5e67a8b70a86d5322bd805668f | |
| parent | 21aa149b0bc7f6321bf03f5f5df75b4d16bdb406 (diff) | |
| download | rust-64edaec6b35ea32e8dffbe27ff123c4a090869a8.tar.gz rust-64edaec6b35ea32e8dffbe27ff123c4a090869a8.zip | |
Always supply span to check_and_apply_linkage, sidestepping need to add `bug!`s to rustc.
| -rw-r--r-- | src/librustc_codegen_llvm/consts.rs | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 5f47108309f..23e2bfe1ad1 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -102,7 +102,7 @@ fn check_and_apply_linkage( 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 { @@ -116,11 +116,7 @@ fn check_and_apply_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`") }; unsafe { // Declare a symbol `foo` with the desired linkage. @@ -136,14 +132,7 @@ fn check_and_apply_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); @@ -240,7 +229,7 @@ impl CodegenCx<'ll, 'tcx> { 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) @@ -260,7 +249,8 @@ impl CodegenCx<'ll, 'tcx> { 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 |
