Skip to content

Commit 42a4419

Browse files
Do not prefer module parents which are doc(hidden) in visibility map
1 parent 6d1100f commit 42a4419

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

+15-5
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,13 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
375375
use std::collections::vec_deque::VecDeque;
376376

377377
let mut visible_parent_map: DefIdMap<DefId> = Default::default();
378-
// This is a secondary visible_parent_map, storing the DefId of parents that re-export
379-
// the child as `_`. Since we prefer parents that don't do this, merge this map at the
380-
// end, only if we're missing any keys from the former.
378+
// This is a secondary visible_parent_map, storing the DefId of
379+
// parents that re-export the child as `_` or module parents
380+
// which are `#[doc(hidden)]`. Since we prefer paths that don't
381+
// do this, merge this map at the end, only if we're missing
382+
// keys from the former.
383+
// This is a rudimentary check that does not catch all cases,
384+
// just the easiest.
381385
let mut fallback_map: DefIdMap<DefId> = Default::default();
382386

383387
// Issue 46112: We want the map to prefer the shortest
@@ -412,6 +416,11 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
412416
return;
413417
}
414418

419+
if ty::util::is_doc_hidden(tcx, parent) {
420+
fallback_map.insert(def_id, parent);
421+
return;
422+
}
423+
415424
match visible_parent_map.entry(def_id) {
416425
Entry::Occupied(mut entry) => {
417426
// If `child` is defined in crate `cnum`, ensure
@@ -439,8 +448,9 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
439448
}
440449
}
441450

442-
// Fill in any missing entries with the (less preferable) path ending in `::_`.
443-
// We still use this path in a diagnostic that suggests importing `::*`.
451+
// Fill in any missing entries with the less preferable path.
452+
// If this path re-exports the child as `_`, we still use this
453+
// path in a diagnostic that suggests importing `::*`.
444454
for (child, parent) in fallback_map {
445455
visible_parent_map.entry(child).or_insert(parent);
446456
}

src/test/ui/suggestions/dont-suggest-doc-hidden-variant-for-enum/hidden-parent.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | let x: Option<i32> = 1i32;
88
|
99
= note: expected enum `Option<i32>`
1010
found type `i32`
11-
help: try wrapping the expression in `hidden_parent::__private::Some`
11+
help: try wrapping the expression in `Some`
1212
|
13-
LL | let x: Option<i32> = hidden_parent::__private::Some(1i32);
14-
| +++++++++++++++++++++++++++++++ +
13+
LL | let x: Option<i32> = Some(1i32);
14+
| +++++ +
1515

1616
error: aborting due to previous error
1717

0 commit comments

Comments
 (0)