Skip to content

Commit 433686d

Browse files
committed
Wrap def_span query to return a SpanId.
1 parent d738c3c commit 433686d

File tree

60 files changed

+225
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+225
-186
lines changed

src/librustc_codegen_llvm/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl CodegenCx<'ll, 'tcx> {
260260
debug!("get_static: sym={} item_attr={:?}", sym, self.tcx.item_attrs(def_id));
261261

262262
let attrs = self.tcx.codegen_fn_attrs(def_id);
263-
let span = self.tcx.def_span(def_id);
263+
let span = self.tcx.real_def_span(def_id);
264264
let g = check_and_apply_linkage(&self, &attrs, ty, sym, span);
265265

266266
// Thread-local statics in some other crate need to *always* be linked

src/librustc_codegen_llvm/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
23132313
// We may want to remove the namespace scope if we're in an extern block (see
23142314
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952).
23152315
let var_scope = get_namespace_for_item(cx, def_id);
2316-
let span = tcx.def_span(def_id);
2316+
let span = tcx.real_def_span(def_id);
23172317

23182318
let (file_metadata, line_number) = if !span.is_dummy() {
23192319
let loc = cx.lookup_debug_loc(span.lo());

src/librustc_codegen_ssa/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
4545
use rustc_session::cgu_reuse_tracker::CguReuse;
4646
use rustc_session::config::{self, EntryFnType};
4747
use rustc_session::Session;
48-
use rustc_span::Span;
48+
use rustc_span::SpanId;
4949
use rustc_symbol_mangling::test as symbol_names_test;
5050
use rustc_target::abi::{Abi, Align, LayoutOf, Scalar, VariantIdx};
5151

@@ -414,7 +414,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
414414

415415
fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
416416
cx: &'a Bx::CodegenCx,
417-
sp: Span,
417+
sp: SpanId,
418418
rust_main: Bx::Value,
419419
rust_main_def_id: LocalDefId,
420420
use_start_lang_item: bool,

src/librustc_infer/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14671467
impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypesVisitor<'tcx> {
14681468
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
14691469
if let Some((kind, def_id)) = TyCategory::from_ty(t) {
1470-
let span = self.tcx.def_span(def_id);
1470+
let span = self.tcx.real_def_span(def_id);
14711471
// Avoid cluttering the output when the "found" and error span overlap:
14721472
//
14731473
// error[E0308]: mismatched types
@@ -1543,7 +1543,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15431543
self.tcx
15441544
.sess
15451545
.source_map()
1546-
.mk_substr_filename(self.tcx.def_span(*def_id)),
1546+
.mk_substr_filename(self.tcx.real_def_span(*def_id)),
15471547
),
15481548
(true, _) => format!(" ({})", ty.sort_string(self.tcx)),
15491549
(false, _) => "".to_string(),

src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::infer::{Subtype, ValuePairs};
66
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
77
use rustc_errors::ErrorReported;
88
use rustc_middle::ty::Ty;
9-
use rustc_span::Span;
9+
use rustc_span::{Span, SpanId};
1010

1111
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
1212
/// Print the error message for lifetime errors when the `impl` doesn't conform to the `trait`.
@@ -47,7 +47,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4747
None
4848
}
4949

50-
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, impl_sp: Span) {
50+
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, impl_sp: SpanId) {
5151
let mut err = self
5252
.tcx()
5353
.sess

src/librustc_infer/infer/lexical_region_resolve/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
664664
.iter()
665665
.map(|&choice_region| var_data.normalize(self.tcx(), choice_region));
666666
if !choice_regions.clone().any(|choice_region| member_region == choice_region) {
667-
let span = self.tcx().def_span(member_constraint.opaque_type_def_id);
667+
let span = self.tcx().real_def_span(member_constraint.opaque_type_def_id);
668668
errors.push(RegionResolutionError::MemberConstraintFailure {
669669
span,
670670
hidden_ty: member_constraint.hidden_ty,

src/librustc_infer/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
3333
use rustc_middle::ty::{ConstVid, FloatVid, IntVid, TyVid};
3434
use rustc_session::config::BorrowckMode;
3535
use rustc_span::symbol::Symbol;
36-
use rustc_span::Span;
36+
use rustc_span::{Span, SpanId};
3737

3838
use std::cell::{Cell, Ref, RefCell};
3939
use std::collections::BTreeMap;
@@ -1579,7 +1579,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15791579
def_id: DefId,
15801580
substs: SubstsRef<'tcx>,
15811581
promoted: Option<mir::Promoted>,
1582-
span: Option<Span>,
1582+
span: Option<SpanId>,
15831583
) -> ConstEvalResult<'tcx> {
15841584
let mut original_values = OriginalQueryValues::default();
15851585
let canonical = self.canonicalize_query(&(param_env, substs), &mut original_values);

src/librustc_interface/callbacks.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ fn track_diagnostic(diagnostic: Diagnostic) -> RealDiagnostic {
3535
let mut diagnostics = diagnostics.lock();
3636
diagnostics.extend(Some(diagnostic.clone()));
3737
}
38-
diagnostic.map_span(|s| match s {
39-
rustc_span::SpanId::Span(s) => s,
40-
rustc_span::SpanId::DefId(d) => icx.tcx.def_span(d),
41-
})
38+
39+
// Ignore dependencies when reifying spans.
40+
let icx = tls::ImplicitCtxt { task_deps: None, ..icx.clone() };
41+
tls::enter_context(&icx, |icx| diagnostic.map_span(|s| icx.tcx.reify_span(s)))
4242
} else {
4343
diagnostic.map_span(|s| match s {
4444
rustc_span::SpanId::Span(s) => s,

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
19771977
if span.is_none() {
19781978
// Point to this field, should be helpful for figuring
19791979
// out where the source of the error is.
1980-
let span = tcx.def_span(field.did);
1980+
let span = tcx.real_def_span(field.did);
19811981
write!(
19821982
&mut msg,
19831983
" (in this {} field)",

src/librustc_macros/src/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
496496
force_query::<crate::ty::query::queries::#name<'_>, _>(
497497
$tcx,
498498
key,
499-
DUMMY_SP,
499+
DUMMY_SPID,
500500
*$dep_node
501501
);
502502
return true;

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
124124
static_mutability => { cdata.static_mutability(def_id.index) }
125125
generator_kind => { cdata.generator_kind(def_id.index) }
126126
def_kind => { cdata.def_kind(def_id.index) }
127-
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
127+
real_def_span => { cdata.get_span(def_id.index, &tcx.sess) }
128128
lookup_stability => {
129129
cdata.get_stability(def_id.index).map(|s| tcx.intern_stability(s))
130130
}

src/librustc_metadata/rmeta/encoder.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl EncodeContext<'tcx> {
622622
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
623623
record!(self.tables.visibility[def_id] <-
624624
ty::Visibility::from_hir(enum_vis, enum_id, self.tcx));
625-
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
625+
record!(self.tables.span[def_id] <- self.tcx.real_def_span(def_id));
626626
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]);
627627
record!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
628628
assert!(f.did.is_local());
@@ -671,7 +671,7 @@ impl EncodeContext<'tcx> {
671671

672672
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
673673
record!(self.tables.visibility[def_id] <- ctor_vis);
674-
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
674+
record!(self.tables.span[def_id] <- self.tcx.real_def_span(def_id));
675675
self.encode_stability(def_id);
676676
self.encode_deprecation(def_id);
677677
self.encode_item_type(def_id);
@@ -706,7 +706,7 @@ impl EncodeContext<'tcx> {
706706

707707
record!(self.tables.kind[def_id] <- EntryKind::Mod(self.lazy(data)));
708708
record!(self.tables.visibility[def_id] <- ty::Visibility::from_hir(vis, id, self.tcx));
709-
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
709+
record!(self.tables.span[def_id] <- self.tcx.real_def_span(def_id));
710710
record!(self.tables.attributes[def_id] <- attrs);
711711
record!(self.tables.children[def_id] <- md.item_ids.iter().map(|item_id| {
712712
tcx.hir().local_def_id(item_id.id).local_def_index
@@ -733,7 +733,7 @@ impl EncodeContext<'tcx> {
733733

734734
record!(self.tables.kind[def_id] <- EntryKind::Field);
735735
record!(self.tables.visibility[def_id] <- field.vis);
736-
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
736+
record!(self.tables.span[def_id] <- self.tcx.real_def_span(def_id));
737737
record!(self.tables.attributes[def_id] <- variant_data.fields()[field_index].attrs);
738738
self.encode_ident_span(def_id, field.ident);
739739
self.encode_stability(def_id);
@@ -774,7 +774,7 @@ impl EncodeContext<'tcx> {
774774

775775
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr));
776776
record!(self.tables.visibility[def_id] <- ctor_vis);
777-
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
777+
record!(self.tables.span[def_id] <- self.tcx.real_def_span(def_id));
778778
self.encode_stability(def_id);
779779
self.encode_deprecation(def_id);
780780
self.encode_item_type(def_id);
@@ -1301,7 +1301,7 @@ impl EncodeContext<'tcx> {
13011301
fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind, encode_type: bool) {
13021302
record!(self.tables.kind[def_id] <- kind);
13031303
record!(self.tables.visibility[def_id] <- ty::Visibility::Public);
1304-
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
1304+
record!(self.tables.span[def_id] <- self.tcx.real_def_span(def_id));
13051305
if encode_type {
13061306
self.encode_item_type(def_id);
13071307
}
@@ -1326,7 +1326,7 @@ impl EncodeContext<'tcx> {
13261326
_ => bug!("closure that is neither generator nor closure"),
13271327
});
13281328
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
1329-
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
1329+
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.real_def_span(def_id));
13301330
record!(self.tables.attributes[def_id.to_def_id()] <- &self.tcx.get_attrs(def_id.to_def_id())[..]);
13311331
self.encode_item_type(def_id.to_def_id());
13321332
if let ty::Closure(def_id, substs) = ty.kind {
@@ -1346,7 +1346,7 @@ impl EncodeContext<'tcx> {
13461346

13471347
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::Const(qualifs, const_data));
13481348
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
1349-
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
1349+
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.real_def_span(def_id));
13501350
self.encode_item_type(def_id.to_def_id());
13511351
self.encode_generics(def_id.to_def_id());
13521352
self.encode_explicit_predicates(def_id.to_def_id());

src/librustc_middle/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub fn struct_lint_level<'s, 'd>(
339339
pub fn in_external_macro(sess: &Session, span: SpanId) -> bool {
340340
let span = match span {
341341
SpanId::Span(span) => span,
342-
SpanId::DefId(def_id) => crate::ty::tls::with(|tcx| tcx.def_span(def_id)),
342+
SpanId::DefId(def_id) => crate::ty::tls::with(|tcx| tcx.real_def_span(def_id)),
343343
};
344344
let expn_data = span.ctxt().outer_expn_data();
345345
match expn_data.kind {

src/librustc_middle/mir/interpret/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub type ConstEvalResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>;
3636

3737
#[derive(Debug)]
3838
pub struct ConstEvalErr<'tcx> {
39-
pub span: Span,
39+
pub span: SpanId,
4040
pub error: crate::mir::interpret::InterpError<'tcx>,
4141
pub stacktrace: Vec<FrameInfo<'tcx>>,
4242
}

src/librustc_middle/mir/interpret/queries.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::mir;
44
use crate::ty::subst::{InternalSubsts, SubstsRef};
55
use crate::ty::{self, TyCtxt};
66
use rustc_hir::def_id::DefId;
7-
use rustc_span::Span;
7+
use rustc_span::SpanId;
88

99
impl<'tcx> TyCtxt<'tcx> {
1010
/// Evaluates a constant without providing any substitutions. This is useful to evaluate consts
@@ -37,7 +37,7 @@ impl<'tcx> TyCtxt<'tcx> {
3737
def_id: DefId,
3838
substs: SubstsRef<'tcx>,
3939
promoted: Option<mir::Promoted>,
40-
span: Option<Span>,
40+
span: Option<SpanId>,
4141
) -> ConstEvalResult<'tcx> {
4242
match ty::Instance::resolve(self, param_env, def_id, substs) {
4343
Ok(Some(instance)) => {
@@ -53,7 +53,7 @@ impl<'tcx> TyCtxt<'tcx> {
5353
self,
5454
param_env: ty::ParamEnv<'tcx>,
5555
instance: ty::Instance<'tcx>,
56-
span: Option<Span>,
56+
span: Option<SpanId>,
5757
) -> ConstEvalResult<'tcx> {
5858
self.const_eval_global_id(param_env, GlobalId { instance, promoted: None }, span)
5959
}
@@ -63,7 +63,7 @@ impl<'tcx> TyCtxt<'tcx> {
6363
self,
6464
param_env: ty::ParamEnv<'tcx>,
6565
cid: GlobalId<'tcx>,
66-
span: Option<Span>,
66+
span: Option<SpanId>,
6767
) -> ConstEvalResult<'tcx> {
6868
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
6969
// improve caching of queries.

src/librustc_middle/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ rustc_queries! {
618618
}
619619

620620
query def_kind(_: DefId) -> DefKind {}
621-
query def_span(_: DefId) -> Span {
621+
query real_def_span(_: DefId) -> Span {
622622
// FIXME(mw): DefSpans are not really inputs since they are derived from
623623
// HIR. But at the moment HIR hashing still contains some hacks that allow
624624
// to make type debuginfo to be source location independent. Declaring

src/librustc_middle/ty/context.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use rustc_session::lint::{Level, Lint};
5959
use rustc_session::Session;
6060
use rustc_span::source_map::MultiSpanId;
6161
use rustc_span::symbol::{kw, sym, Symbol};
62-
use rustc_span::Span;
62+
use rustc_span::{Span, SpanId};
6363
use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx};
6464
use rustc_target::spec::abi;
6565

@@ -1225,6 +1225,17 @@ impl<'tcx> TyCtxt<'tcx> {
12251225
self.features_query(LOCAL_CRATE)
12261226
}
12271227

1228+
pub fn def_span(self, id: impl ty::query::IntoQueryParam<rustc_span::def_id::DefId>) -> SpanId {
1229+
SpanId::DefId(id.into_query_param())
1230+
}
1231+
1232+
pub fn reify_span(self, sp: SpanId) -> Span {
1233+
match sp {
1234+
SpanId::Span(sp) => sp,
1235+
SpanId::DefId(id) => self.real_def_span(id),
1236+
}
1237+
}
1238+
12281239
pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
12291240
if let Some(id) = id.as_local() { self.hir().def_key(id) } else { self.cstore.def_key(id) }
12301241
}

src/librustc_middle/ty/error.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,11 @@ impl<'tcx> TyCtxt<'tcx> {
381381
}
382382
(ty::Param(expected), ty::Param(found)) => {
383383
let generics = self.generics_of(body_owner_def_id);
384-
let e_span = self.def_span(generics.type_param(expected, self).def_id);
384+
let e_span = self.real_def_span(generics.type_param(expected, self).def_id);
385385
if !sp.contains(e_span) {
386386
db.span_label(e_span, "expected type parameter");
387387
}
388-
let f_span = self.def_span(generics.type_param(found, self).def_id);
388+
let f_span = self.real_def_span(generics.type_param(found, self).def_id);
389389
if !sp.contains(f_span) {
390390
db.span_label(f_span, "found type parameter");
391391
}
@@ -404,7 +404,7 @@ impl<'tcx> TyCtxt<'tcx> {
404404
}
405405
(ty::Param(p), ty::Projection(proj)) | (ty::Projection(proj), ty::Param(p)) => {
406406
let generics = self.generics_of(body_owner_def_id);
407-
let p_span = self.def_span(generics.type_param(p, self).def_id);
407+
let p_span = self.real_def_span(generics.type_param(p, self).def_id);
408408
if !sp.contains(p_span) {
409409
db.span_label(p_span, "this type parameter");
410410
}
@@ -446,7 +446,7 @@ impl<'tcx> TyCtxt<'tcx> {
446446
(ty::Param(p), ty::Dynamic(..) | ty::Opaque(..))
447447
| (ty::Dynamic(..) | ty::Opaque(..), ty::Param(p)) => {
448448
let generics = self.generics_of(body_owner_def_id);
449-
let p_span = self.def_span(generics.type_param(p, self).def_id);
449+
let p_span = self.real_def_span(generics.type_param(p, self).def_id);
450450
if !sp.contains(p_span) {
451451
db.span_label(p_span, "this type parameter");
452452
}
@@ -486,7 +486,7 @@ impl<T> Trait<T> for X {
486486
}
487487
(ty::Param(p), _) | (_, ty::Param(p)) => {
488488
let generics = self.generics_of(body_owner_def_id);
489-
let p_span = self.def_span(generics.type_param(p, self).def_id);
489+
let p_span = self.real_def_span(generics.type_param(p, self).def_id);
490490
if !sp.contains(p_span) {
491491
db.span_label(p_span, "this type parameter");
492492
}
@@ -696,7 +696,7 @@ impl<T> Trait<T> for X {
696696
// a return type. This can occur when dealing with `TryStream` (#71035).
697697
if self.constrain_associated_type_structured_suggestion(
698698
db,
699-
self.def_span(def_id),
699+
self.real_def_span(def_id),
700700
&assoc,
701701
values.found,
702702
&msg,
@@ -766,7 +766,7 @@ fn foo(&self) -> Self::T { String::new() }
766766
if item_def_id == proj_ty_item_def_id =>
767767
{
768768
Some((
769-
self.sess.source_map().guess_head_span(self.def_span(item.def_id)),
769+
self.sess.source_map().guess_head_span(self.real_def_span(item.def_id)),
770770
format!("consider calling `{}`", self.def_path_str(item.def_id)),
771771
))
772772
}

src/librustc_middle/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ pub trait PrettyPrinter<'tcx>:
895895
}
896896
_ => {
897897
if did.is_local() {
898-
let span = self.tcx().def_span(did);
898+
let span = self.tcx().real_def_span(did);
899899
if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span)
900900
{
901901
p!(write("{}", snip))
@@ -1347,7 +1347,7 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
13471347
// pretty printing some span information. This should
13481348
// only occur very early in the compiler pipeline.
13491349
let parent_def_id = DefId { index: key.parent.unwrap(), ..def_id };
1350-
let span = self.tcx.def_span(def_id);
1350+
let span = self.tcx.real_def_span(def_id);
13511351

13521352
self = self.print_def_path(parent_def_id, &[])?;
13531353

0 commit comments

Comments
 (0)