diff options
| author | bors <bors@rust-lang.org> | 2020-11-04 17:17:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-11-04 17:17:01 +0000 |
| commit | 89631663b7ad2d46d3e4f52bcfa7bee2be9eb82b (patch) | |
| tree | 99b68ba8b6239710db5c34b0d84b52feed7a97a2 /compiler/rustc_codegen_ssa/src/base.rs | |
| parent | 75f1db1102076e416e1154b241b4fc95c01c0d7b (diff) | |
| parent | caf9131e652cb8d92a1f9f3f5b02bc2ca51d3ed5 (diff) | |
| download | rust-89631663b7ad2d46d3e4f52bcfa7bee2be9eb82b.tar.gz rust-89631663b7ad2d46d3e4f52bcfa7bee2be9eb82b.zip | |
Auto merge of #78280 - bugadani:span, r=lcnr
Codegen: Query span as late as possible
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/base.rs')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/base.rs | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 2486dde0e06..afb407b35be 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -46,7 +46,6 @@ use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_session::config::{self, EntryFnType}; use rustc_session::utils::NativeLibKind; use rustc_session::Session; -use rustc_span::Span; use rustc_symbol_mangling::test as symbol_names_test; use rustc_target::abi::{Align, LayoutOf, VariantIdx}; @@ -364,11 +363,7 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx, ) -> Option<Bx::Function> { - let (main_def_id, span) = match cx.tcx().entry_fn(LOCAL_CRATE) { - Some((def_id, _)) => (def_id, cx.tcx().def_span(def_id)), - None => return None, - }; - + let main_def_id = cx.tcx().entry_fn(LOCAL_CRATE).map(|(def_id, _)| def_id)?; let instance = Instance::mono(cx.tcx(), main_def_id.to_def_id()); if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) { @@ -381,12 +376,11 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( return cx.tcx().entry_fn(LOCAL_CRATE).map(|(_, et)| { let use_start_lang_item = EntryFnType::Start != et; - create_entry_fn::<Bx>(cx, span, main_llfn, main_def_id, use_start_lang_item) + create_entry_fn::<Bx>(cx, main_llfn, main_def_id, use_start_lang_item) }); fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx, - sp: Span, rust_main: Bx::Value, rust_main_def_id: LocalDefId, use_start_lang_item: bool, @@ -411,8 +405,9 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( Some(llfn) => llfn, None => { // FIXME: We should be smart and show a better diagnostic here. + let span = cx.tcx().def_span(rust_main_def_id); cx.sess() - .struct_span_err(sp, "entry symbol `main` declared multiple times") + .struct_span_err(span, "entry symbol `main` declared multiple times") .help("did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead") .emit(); cx.sess().abort_if_errors(); |
