Skip to content

Commit a04e787

Browse files
committed
Use source_span query instead of passing the untracked vec around
1 parent a6b381a commit a04e787

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ use rustc_errors::{struct_span_err, SuggestionStyle};
1212
use rustc_feature::BUILTIN_ATTRIBUTES;
1313
use rustc_hir::def::Namespace::{self, *};
1414
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PerNS};
15-
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
15+
use rustc_hir::def_id::{DefId, CRATE_DEF_ID, LOCAL_CRATE};
1616
use rustc_hir::PrimTy;
17-
use rustc_index::vec::IndexVec;
1817
use rustc_middle::bug;
19-
use rustc_middle::ty::DefIdTree;
18+
use rustc_middle::ty::{DefIdTree, TyCtxt};
2019
use rustc_session::lint::builtin::ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE;
2120
use rustc_session::lint::builtin::MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS;
2221
use rustc_session::lint::BuiltinLintDiagnostics;
@@ -154,8 +153,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
154153

155154
if !candidates.is_empty() {
156155
show_candidates(
157-
&self.tcx.sess,
158-
&self.tcx.untracked().source_span.read(),
156+
self.tcx,
159157
&mut err,
160158
span,
161159
&candidates,
@@ -687,8 +685,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
687685
err.span_help(span, &help_msg);
688686
}
689687
show_candidates(
690-
&self.tcx.sess,
691-
&self.tcx.untracked().source_span.read(),
688+
self.tcx,
692689
&mut err,
693690
Some(span),
694691
&import_suggestions,
@@ -1352,8 +1349,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13521349
let import_suggestions =
13531350
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
13541351
show_candidates(
1355-
&self.tcx.sess,
1356-
&self.tcx.untracked().source_span.read(),
1352+
self.tcx,
13571353
err,
13581354
None,
13591355
&import_suggestions,
@@ -2358,8 +2354,7 @@ pub(crate) enum DiagnosticMode {
23582354
}
23592355

23602356
pub(crate) fn import_candidates(
2361-
session: &Session,
2362-
source_span: &IndexVec<LocalDefId, Span>,
2357+
tcx: TyCtxt<'_>,
23632358
err: &mut Diagnostic,
23642359
// This is `None` if all placement locations are inside expansions
23652360
use_placement_span: Option<Span>,
@@ -2368,8 +2363,7 @@ pub(crate) fn import_candidates(
23682363
append: &str,
23692364
) {
23702365
show_candidates(
2371-
session,
2372-
source_span,
2366+
tcx,
23732367
err,
23742368
use_placement_span,
23752369
candidates,
@@ -2385,8 +2379,7 @@ pub(crate) fn import_candidates(
23852379
/// entities with that name in all crates. This method allows outputting the
23862380
/// results of this search in a programmer-friendly way
23872381
fn show_candidates(
2388-
session: &Session,
2389-
source_span: &IndexVec<LocalDefId, Span>,
2382+
tcx: TyCtxt<'_>,
23902383
err: &mut Diagnostic,
23912384
// This is `None` if all placement locations are inside expansions
23922385
use_placement_span: Option<Span>,
@@ -2511,8 +2504,8 @@ fn show_candidates(
25112504
);
25122505

25132506
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
2514-
let span = source_span[local_def_id];
2515-
let span = session.source_map().guess_head_span(span);
2507+
let span = tcx.source_span(local_def_id);
2508+
let span = tcx.sess.source_map().guess_head_span(span);
25162509
let mut multi_span = MultiSpan::from_span(span);
25172510
multi_span.push_span_label(span, "not accessible");
25182511
err.span_note(multi_span, &msg);
@@ -2542,8 +2535,8 @@ fn show_candidates(
25422535
let mut spans = Vec::new();
25432536
for (name, _, def_id, _) in &inaccessible_path_strings {
25442537
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
2545-
let span = source_span[local_def_id];
2546-
let span = session.source_map().guess_head_span(span);
2538+
let span = tcx.source_span(local_def_id);
2539+
let span = tcx.sess.source_map().guess_head_span(span);
25472540
spans.push((name, span));
25482541
} else {
25492542
if !has_colon {

compiler/rustc_resolve/src/imports.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
548548
if let Some(candidates) = &err.candidates {
549549
match &import.kind {
550550
ImportKind::Single { nested: false, source, target, .. } => import_candidates(
551-
self.r.tcx.sess,
552-
&self.r.tcx.untracked().source_span.read(),
551+
self.r.tcx,
553552
&mut diag,
554553
Some(err.span),
555554
&candidates,
@@ -561,8 +560,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
561560
),
562561
ImportKind::Single { nested: true, source, target, .. } => {
563562
import_candidates(
564-
self.r.tcx.sess,
565-
&self.r.tcx.untracked().source_span.read(),
563+
self.r.tcx,
566564
&mut diag,
567565
None,
568566
&candidates,

0 commit comments

Comments
 (0)