Skip to content

Commit 464edf2

Browse files
committed
fix: Check the fallback map before queueing child in visible_parent_map BFS
1 parent 5048696 commit 464edf2

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
472472
// the former.
473473
// This is a rudimentary check that does not catch all cases,
474474
// just the easiest.
475-
let mut fallback_map: Vec<(DefId, DefId)> = Default::default();
475+
let mut fallback_map: DefIdMap<DefId> = Default::default();
476476

477477
// Issue 46112: We want the map to prefer the shortest
478478
// paths when reporting the path to an item. Therefore we
@@ -533,14 +533,24 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
533533
}
534534
}
535535
Entry::Vacant(entry) => {
536+
if !fallback {
537+
entry.insert(parent);
538+
}
539+
540+
// Make sure that we have not already explored this child
541+
// through a previous fallback entry further up the BFS,
542+
// in which case we do not want to put it back into the BFS queue,
543+
// nor record a new fallback parent.
544+
if fallback_map.contains_key(&def_id) {
545+
return;
546+
}
547+
536548
if fallback {
537549
// We do all of the same steps to fallback entries as to
538550
// preferred entries, except for recording them in a separate map.
539551
// It is important to not return early in the fallback cases to
540552
// ensure that we extend the BFS to the children of fallback items.
541-
fallback_map.push((def_id, parent));
542-
} else {
543-
entry.insert(parent);
553+
fallback_map.insert(def_id, parent);
544554
}
545555

546556
if child.res.module_like_def_id().is_some() {
@@ -560,10 +570,11 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
560570
// Fill in any missing entries with the less preferable path.
561571
// If this path re-exports the child as `_`, we still use this
562572
// path in a diagnostic that suggests importing `::*`.
563-
564-
for (child, parent) in fallback_map {
565-
visible_parent_map.entry(child).or_insert(parent);
566-
}
573+
tcx.with_stable_hashing_context(|mut hcx| {
574+
for (child, parent) in fallback_map.into_sorted(&mut hcx, true) {
575+
visible_parent_map.entry(child).or_insert(parent);
576+
}
577+
});
567578

568579
visible_parent_map
569580
},

0 commit comments

Comments
 (0)