Skip to content

Commit bfb7bb9

Browse files
committed
Do not sort DefIds in diagnostics
1 parent ab82904 commit bfb7bb9

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,7 @@ pub(crate) fn import_candidates(
27302730
);
27312731
}
27322732

2733-
type PathString<'a> = (String, &'a str, Option<DefId>, &'a Option<String>, bool);
2733+
type PathString<'a> = (String, &'a str, Option<Span>, &'a Option<String>, bool);
27342734

27352735
/// When an entity with a given name is not available in scope, we search for
27362736
/// entities with that name in all crates. This method allows outputting the
@@ -2762,7 +2762,7 @@ fn show_candidates(
27622762
accessible_path_strings.push((
27632763
pprust::path_to_string(&c.path),
27642764
c.descr,
2765-
c.did,
2765+
c.did.and_then(|did| Some(tcx.source_span(did.as_local()?))),
27662766
&c.note,
27672767
c.via_import,
27682768
))
@@ -2771,7 +2771,7 @@ fn show_candidates(
27712771
inaccessible_path_strings.push((
27722772
pprust::path_to_string(&c.path),
27732773
c.descr,
2774-
c.did,
2774+
c.did.and_then(|did| Some(tcx.source_span(did.as_local()?))),
27752775
&c.note,
27762776
c.via_import,
27772777
))
@@ -2889,15 +2889,14 @@ fn show_candidates(
28892889
} else if !(inaccessible_path_strings.is_empty() || matches!(mode, DiagMode::Import { .. })) {
28902890
let prefix =
28912891
if let DiagMode::Pattern = mode { "you might have meant to match on " } else { "" };
2892-
if let [(name, descr, def_id, note, _)] = &inaccessible_path_strings[..] {
2892+
if let [(name, descr, source_span, note, _)] = &inaccessible_path_strings[..] {
28932893
let msg = format!(
28942894
"{prefix}{descr} `{name}`{} exists but is inaccessible",
28952895
if let DiagMode::Pattern = mode { ", which" } else { "" }
28962896
);
28972897

2898-
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
2899-
let span = tcx.source_span(local_def_id);
2900-
let span = tcx.sess.source_map().guess_head_span(span);
2898+
if let Some(source_span) = source_span {
2899+
let span = tcx.sess.source_map().guess_head_span(*source_span);
29012900
let mut multi_span = MultiSpan::from_span(span);
29022901
multi_span.push_span_label(span, "not accessible");
29032902
err.span_note(multi_span, msg);
@@ -2925,10 +2924,9 @@ fn show_candidates(
29252924
let mut has_colon = false;
29262925

29272926
let mut spans = Vec::new();
2928-
for (name, _, def_id, _, _) in &inaccessible_path_strings {
2929-
if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) {
2930-
let span = tcx.source_span(local_def_id);
2931-
let span = tcx.sess.source_map().guess_head_span(span);
2927+
for (name, _, source_span, _, _) in &inaccessible_path_strings {
2928+
if let Some(source_span) = source_span {
2929+
let span = tcx.sess.source_map().guess_head_span(*source_span);
29322930
spans.push((name, span));
29332931
} else {
29342932
if !has_colon {

0 commit comments

Comments
 (0)