Skip to content

Commit 3273cce

Browse files
Fix spans
1 parent 0f7f3f4 commit 3273cce

File tree

11 files changed

+36
-36
lines changed

11 files changed

+36
-36
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
376376
ty::ParamEnv::reveal_all(),
377377
def_id,
378378
fn_args,
379-
Some(source_info.span),
379+
source_info.span,
380380
)
381381
.polymorphize(fx.tcx);
382382

compiler/rustc_codegen_cranelift/src/main_shim.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_middle::ty::AssocKind;
44
use rustc_middle::ty::GenericArg;
55
use rustc_session::config::{sigpipe, EntryFnType};
66
use rustc_span::symbol::Ident;
7+
use rustc_span::DUMMY_SP;
78

89
use crate::prelude::*;
910

@@ -119,7 +120,7 @@ pub(crate) fn maybe_create_entry_wrapper(
119120
ParamEnv::reveal_all(),
120121
report.def_id,
121122
tcx.mk_args(&[GenericArg::from(main_ret_ty)]),
122-
None,
123+
DUMMY_SP,
123124
)
124125
.polymorphize(tcx);
125126

@@ -145,7 +146,7 @@ pub(crate) fn maybe_create_entry_wrapper(
145146
ParamEnv::reveal_all(),
146147
start_def_id,
147148
tcx.mk_args(&[main_ret_ty.into()]),
148-
None,
149+
DUMMY_SP,
149150
)
150151
.polymorphize(tcx);
151152
let start_func_id = import_function(tcx, m, start_instance);

compiler/rustc_codegen_gcc/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::ty::layout::{
1717
};
1818
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
1919
use rustc_session::Session;
20-
use rustc_span::{source_map::respan, Span};
20+
use rustc_span::{source_map::respan, Span, DUMMY_SP};
2121
use rustc_target::abi::{
2222
call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx,
2323
};
@@ -479,7 +479,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
479479
ty::ParamEnv::reveal_all(),
480480
def_id,
481481
ty::List::empty(),
482-
None,
482+
DUMMY_SP,
483483
);
484484

485485
let symbol_name = tcx.symbol_name(instance).name;

compiler/rustc_codegen_llvm/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_session::config::{BranchProtection, CFGuard, CFProtection};
2828
use rustc_session::config::{CrateType, DebugInfo, PAuthKey, PacRet};
2929
use rustc_session::Session;
3030
use rustc_span::source_map::Spanned;
31-
use rustc_span::Span;
31+
use rustc_span::{Span, DUMMY_SP};
3232
use rustc_target::abi::{call::FnAbi, HasDataLayout, TargetDataLayout, VariantIdx};
3333
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
3434
use smallvec::SmallVec;
@@ -580,7 +580,7 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
580580
ty::ParamEnv::reveal_all(),
581581
def_id,
582582
ty::List::empty(),
583-
None,
583+
DUMMY_SP,
584584
)),
585585
_ => {
586586
let name = name.unwrap_or("rust_eh_personality");

compiler/rustc_codegen_ssa/src/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
3737
use rustc_session::config::{self, CrateType, EntryFnType, OptLevel, OutputType};
3838
use rustc_session::Session;
3939
use rustc_span::symbol::sym;
40-
use rustc_span::Symbol;
40+
use rustc_span::{Symbol, DUMMY_SP};
4141
use rustc_target::abi::FIRST_VARIANT;
4242

4343
use std::cmp;
@@ -467,7 +467,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
467467
ty::ParamEnv::reveal_all(),
468468
start_def_id,
469469
cx.tcx().mk_args(&[main_ret_ty.into()]),
470-
None,
470+
DUMMY_SP,
471471
);
472472
let start_fn = cx.get_fn_addr(start_instance);
473473

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
842842
ty::ParamEnv::reveal_all(),
843843
def_id,
844844
args,
845-
Some(fn_span),
845+
fn_span,
846846
)
847847
.polymorphize(bx.tcx()),
848848
),

compiler/rustc_const_eval/src/const_eval/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
253253
ty::ParamEnv::reveal_all(),
254254
const_def_id,
255255
instance.args,
256-
Some(self.find_closest_untracked_caller_location()),
256+
self.cur_span(),
257257
);
258258

259259
return Ok(Some(new_instance));

compiler/rustc_const_eval/src/interpret/terminator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
888888
self.param_env,
889889
def_id,
890890
instance.args.rebase_onto(tcx, trait_def_id, concrete_trait_ref.args),
891+
self.cur_span(),
891892
);
892893
assert_eq!(fn_inst, concrete_method);
893894
}

compiler/rustc_middle/src/ty/instance.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,14 @@ impl<'tcx> Instance<'tcx> {
547547
param_env: ty::ParamEnv<'tcx>,
548548
def_id: DefId,
549549
args: GenericArgsRef<'tcx>,
550-
span: Option<Span>,
550+
span: Span,
551551
) -> Instance<'tcx> {
552+
// We compute the span lazily, to avoid unnecessary query calls.
553+
// If `span` is a DUMMY_SP, and the def id is local, then use the
554+
// def span of the def id.
555+
let span_or_local_def_span =
556+
|| if span.is_dummy() && def_id.is_local() { tcx.def_span(def_id) } else { span };
557+
552558
match ty::Instance::resolve(tcx, param_env, def_id, args) {
553559
Ok(Some(instance)) => instance,
554560
Ok(None) => {
@@ -567,22 +573,22 @@ impl<'tcx> Instance<'tcx> {
567573
// We don't use `def_span(def_id)` so that diagnostics point
568574
// to the crate root during mono instead of to foreign items.
569575
// This is arguably better.
570-
span: span.unwrap_or(DUMMY_SP),
576+
span: span_or_local_def_span(),
571577
shrunk,
572578
was_written,
573579
path,
574580
type_length,
575581
});
576582
} else {
577583
span_bug!(
578-
span.unwrap_or(tcx.def_span(def_id)),
584+
span_or_local_def_span(),
579585
"failed to resolve instance for {}",
580586
tcx.def_path_str_with_args(def_id, args)
581587
)
582588
}
583589
}
584590
instance => span_bug!(
585-
span.unwrap_or(tcx.def_span(def_id)),
591+
span_or_local_def_span(),
586592
"failed to resolve instance for {}: {instance:#?}",
587593
tcx.def_path_str_with_args(def_id, args)
588594
),
@@ -642,6 +648,7 @@ impl<'tcx> Instance<'tcx> {
642648
param_env: ty::ParamEnv<'tcx>,
643649
def_id: DefId,
644650
args: GenericArgsRef<'tcx>,
651+
span: Span,
645652
) -> Instance<'tcx> {
646653
debug!("resolve_for_vtable(def_id={:?}, args={:?})", def_id, args);
647654
let fn_sig = tcx.fn_sig(def_id).instantiate_identity();
@@ -654,7 +661,7 @@ impl<'tcx> Instance<'tcx> {
654661
return Instance { def: InstanceKind::VTableShim(def_id), args };
655662
}
656663

657-
let mut resolved = Instance::expect_resolve(tcx, param_env, def_id, args, None);
664+
let mut resolved = Instance::expect_resolve(tcx, param_env, def_id, args, span);
658665

659666
let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::Vtable);
660667
match resolved.def {
@@ -731,13 +738,13 @@ impl<'tcx> Instance<'tcx> {
731738
pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
732739
let def_id = tcx.require_lang_item(LangItem::DropInPlace, None);
733740
let args = tcx.mk_args(&[ty.into()]);
734-
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, None)
741+
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, DUMMY_SP)
735742
}
736743

737744
pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
738745
let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, None);
739746
let args = tcx.mk_args(&[ty.into()]);
740-
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, None)
747+
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, DUMMY_SP)
741748
}
742749

743750
#[instrument(level = "debug", skip(tcx), ret)]

compiler/rustc_monomorphize/src/collector.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -853,13 +853,7 @@ fn visit_fn_use<'tcx>(
853853
) {
854854
if let ty::FnDef(def_id, args) = *ty.kind() {
855855
let instance = if is_direct_call {
856-
ty::Instance::expect_resolve(
857-
tcx,
858-
ty::ParamEnv::reveal_all(),
859-
def_id,
860-
args,
861-
Some(source),
862-
)
856+
ty::Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, source)
863857
} else {
864858
match ty::Instance::resolve_for_fn_ptr(tcx, ty::ParamEnv::reveal_all(), def_id, args) {
865859
Some(instance) => instance,
@@ -1261,13 +1255,8 @@ fn visit_mentioned_item<'tcx>(
12611255
match *item {
12621256
MentionedItem::Fn(ty) => {
12631257
if let ty::FnDef(def_id, args) = *ty.kind() {
1264-
let instance = Instance::expect_resolve(
1265-
tcx,
1266-
ty::ParamEnv::reveal_all(),
1267-
def_id,
1268-
args,
1269-
Some(span),
1270-
);
1258+
let instance =
1259+
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, span);
12711260
// `visit_instance_use` was written for "used" item collection but works just as well
12721261
// for "mentioned" item collection.
12731262
// We can set `is_direct_call`; that just means we'll skip a bunch of shims that anyway
@@ -1492,7 +1481,7 @@ impl<'v> RootCollector<'_, 'v> {
14921481
ty::ParamEnv::reveal_all(),
14931482
start_def_id,
14941483
self.tcx.mk_args(&[main_ret_ty.into()]),
1495-
None,
1484+
DUMMY_SP,
14961485
);
14971486

14981487
self.output.push(create_fn_mono_item(self.tcx, start_instance, DUMMY_SP));
@@ -1561,9 +1550,10 @@ fn create_mono_items_for_default_impls<'tcx>(
15611550
}
15621551

15631552
// As mentioned above, the method is legal to eagerly instantiate if it
1564-
// only has lifetime generic parameters. This is validated by
1553+
// only has lifetime generic parameters. This is validated by calling
1554+
// `own_requires_monomorphization` on both the impl and method.
15651555
let args = trait_ref.args.extend_to(tcx, method.def_id, only_region_params);
1566-
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, None);
1556+
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, DUMMY_SP);
15671557

15681558
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
15691559
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, instance) {

compiler/rustc_trait_selection/src/traits/vtable.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::bug;
66
use rustc_middle::query::Providers;
77
use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt, Upcast, VtblEntry};
88
use rustc_middle::ty::{GenericArgs, TypeVisitableExt};
9-
use rustc_span::{sym, Span};
9+
use rustc_span::{sym, Span, DUMMY_SP};
1010
use smallvec::{smallvec, SmallVec};
1111

1212
use std::fmt::Debug;
@@ -290,6 +290,7 @@ fn vtable_entries<'tcx>(
290290
ty::ParamEnv::reveal_all(),
291291
def_id,
292292
args,
293+
DUMMY_SP,
293294
);
294295

295296
VtblEntry::Method(instance)

0 commit comments

Comments
 (0)