Skip to content

Commit 3ca1c31

Browse files
authored
Rollup merge of #99698 - compiler-errors:no-doc-hidden, r=cjgillot
Prefer visibility map parents that are not `doc(hidden)` first Far simpler approach to #98876. This only fixes the case where the parent is `doc(hidden)`, not where the child is `doc(hidden)` since I don't know how to get the attrs on the import statement given a `ModChild`... I'll try to follow up with that, but this is a good first step.
2 parents 1ff84f0 + 42a4419 commit 3ca1c31

File tree

7 files changed

+84
-5
lines changed

7 files changed

+84
-5
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
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_type = "lib"]
2+
3+
extern crate core;
4+
5+
pub mod __private {
6+
#[doc(hidden)]
7+
pub use core::option::Option::{self, None, Some};
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_type = "lib"]
2+
3+
extern crate core;
4+
5+
#[doc(hidden)]
6+
pub mod __private {
7+
pub use core::option::Option::{self, None, Some};
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// aux-build:hidden-child.rs
2+
3+
// FIXME(compiler-errors): This currently suggests the wrong thing.
4+
// UI test exists to track the problem.
5+
6+
extern crate hidden_child;
7+
8+
fn main() {
9+
let x: Option<i32> = 1i32; //~ ERROR mismatched types
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/hidden-child.rs:9:26
3+
|
4+
LL | let x: Option<i32> = 1i32;
5+
| ----------- ^^^^ expected enum `Option`, found `i32`
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected enum `Option<i32>`
10+
found type `i32`
11+
help: try wrapping the expression in `hidden_child::__private::Some`
12+
|
13+
LL | let x: Option<i32> = hidden_child::__private::Some(1i32);
14+
| ++++++++++++++++++++++++++++++ +
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// aux-build:hidden-parent.rs
2+
3+
extern crate hidden_parent;
4+
5+
fn main() {
6+
let x: Option<i32> = 1i32; //~ ERROR mismatched types
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/hidden-parent.rs:6:26
3+
|
4+
LL | let x: Option<i32> = 1i32;
5+
| ----------- ^^^^ expected enum `Option`, found `i32`
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected enum `Option<i32>`
10+
found type `i32`
11+
help: try wrapping the expression in `Some`
12+
|
13+
LL | let x: Option<i32> = Some(1i32);
14+
| +++++ +
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)