mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-10 14:02:57 +00:00
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.
This commit is contained in:
commit
3ca1c3100d
@ -375,9 +375,13 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
||||
use std::collections::vec_deque::VecDeque;
|
||||
|
||||
let mut visible_parent_map: DefIdMap<DefId> = Default::default();
|
||||
// This is a secondary visible_parent_map, storing the DefId of parents that re-export
|
||||
// the child as `_`. Since we prefer parents that don't do this, merge this map at the
|
||||
// end, only if we're missing any keys from the former.
|
||||
// This is a secondary visible_parent_map, storing the DefId of
|
||||
// parents that re-export the child as `_` or module parents
|
||||
// which are `#[doc(hidden)]`. Since we prefer paths that don't
|
||||
// do this, merge this map at the end, only if we're missing
|
||||
// keys from the former.
|
||||
// This is a rudimentary check that does not catch all cases,
|
||||
// just the easiest.
|
||||
let mut fallback_map: DefIdMap<DefId> = Default::default();
|
||||
|
||||
// Issue 46112: We want the map to prefer the shortest
|
||||
@ -412,6 +416,11 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ty::util::is_doc_hidden(tcx, parent) {
|
||||
fallback_map.insert(def_id, parent);
|
||||
return;
|
||||
}
|
||||
|
||||
match visible_parent_map.entry(def_id) {
|
||||
Entry::Occupied(mut entry) => {
|
||||
// If `child` is defined in crate `cnum`, ensure
|
||||
@ -439,8 +448,9 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fill in any missing entries with the (less preferable) path ending in `::_`.
|
||||
// We still use this path in a diagnostic that suggests importing `::*`.
|
||||
// Fill in any missing entries with the less preferable path.
|
||||
// If this path re-exports the child as `_`, we still use this
|
||||
// path in a diagnostic that suggests importing `::*`.
|
||||
for (child, parent) in fallback_map {
|
||||
visible_parent_map.entry(child).or_insert(parent);
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
#![crate_type = "lib"]
|
||||
|
||||
extern crate core;
|
||||
|
||||
pub mod __private {
|
||||
#[doc(hidden)]
|
||||
pub use core::option::Option::{self, None, Some};
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
#![crate_type = "lib"]
|
||||
|
||||
extern crate core;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __private {
|
||||
pub use core::option::Option::{self, None, Some};
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
// aux-build:hidden-child.rs
|
||||
|
||||
// FIXME(compiler-errors): This currently suggests the wrong thing.
|
||||
// UI test exists to track the problem.
|
||||
|
||||
extern crate hidden_child;
|
||||
|
||||
fn main() {
|
||||
let x: Option<i32> = 1i32; //~ ERROR mismatched types
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/hidden-child.rs:9:26
|
||||
|
|
||||
LL | let x: Option<i32> = 1i32;
|
||||
| ----------- ^^^^ expected enum `Option`, found `i32`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected enum `Option<i32>`
|
||||
found type `i32`
|
||||
help: try wrapping the expression in `hidden_child::__private::Some`
|
||||
|
|
||||
LL | let x: Option<i32> = hidden_child::__private::Some(1i32);
|
||||
| ++++++++++++++++++++++++++++++ +
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
@ -0,0 +1,7 @@
|
||||
// aux-build:hidden-parent.rs
|
||||
|
||||
extern crate hidden_parent;
|
||||
|
||||
fn main() {
|
||||
let x: Option<i32> = 1i32; //~ ERROR mismatched types
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/hidden-parent.rs:6:26
|
||||
|
|
||||
LL | let x: Option<i32> = 1i32;
|
||||
| ----------- ^^^^ expected enum `Option`, found `i32`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected enum `Option<i32>`
|
||||
found type `i32`
|
||||
help: try wrapping the expression in `Some`
|
||||
|
|
||||
LL | let x: Option<i32> = Some(1i32);
|
||||
| +++++ +
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user