Auto merge of #113958 - lukas-code:doc-links, r=GuillaumeGomez,petrochenkov
fix intra-doc links on nested `use` and `extern crate` items This PR fixes two rustdoc ICEs that happen if there are any intra-doc links on nested `use` or `extern crate` items, for example: ```rust /// Re-export [`fmt`] and [`io`]. pub use std::{fmt, io}; // "nested" use = use with braces /// Re-export [`std`]. pub extern crate std; ``` Nested use items were incorrectly considered private and therefore didn't have their intra-doc links resolved. I fixed this by always resolving intra-doc links for nested `use` items that are declared `pub`. <details> During AST->HIR lowering, nested `use` items are desugared like this: ```rust pub use std::{}; // "list stem" pub use std::fmt; pub use std::io; ``` Each of these HIR nodes has it's own effective visibility and the list stem is always considered private. To check the effective visibility of an AST node, the AST node is mapped to a HIR node with `Resolver::local_def_id`, which returns the (private) list stem for nested use items. </details> For `extern crate`, there was a hack in rustdoc that stored the `DefId` of the crate itself in the cleaned item, instead of the `DefId` of the `extern crate` item. This made rustdoc look at the resolved links of the extern crate's crate root instead of the `extern crate` item. I've removed this hack and instead translate the `DefId` in the appropriate places. As as side effect of fixing `extern crate`, i've turned ```rust #[doc(masked)] extern crate self as _; ``` into a no-op instead of hiding all trait impls. Proper verification for `doc(masked)` is included as a bonus. fixes https://github.com/rust-lang/rust/issues/113896
This commit is contained in:
commit
beef07fe8f
17 changed files with 246 additions and 144 deletions
|
@ -549,6 +549,7 @@ enum MaybeExported<'a> {
|
|||
Ok(NodeId),
|
||||
Impl(Option<DefId>),
|
||||
ImplItem(Result<DefId, &'a Visibility>),
|
||||
NestedUse(&'a Visibility),
|
||||
}
|
||||
|
||||
impl MaybeExported<'_> {
|
||||
|
@ -559,7 +560,9 @@ impl MaybeExported<'_> {
|
|||
trait_def_id.as_local()
|
||||
}
|
||||
MaybeExported::Impl(None) => return true,
|
||||
MaybeExported::ImplItem(Err(vis)) => return vis.kind.is_pub(),
|
||||
MaybeExported::ImplItem(Err(vis)) | MaybeExported::NestedUse(vis) => {
|
||||
return vis.kind.is_pub();
|
||||
}
|
||||
};
|
||||
def_id.map_or(true, |def_id| r.effective_visibilities.is_exported(def_id))
|
||||
}
|
||||
|
@ -2284,7 +2287,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
fn resolve_item(&mut self, item: &'ast Item) {
|
||||
let mod_inner_docs =
|
||||
matches!(item.kind, ItemKind::Mod(..)) && rustdoc::inner_docs(&item.attrs);
|
||||
if !mod_inner_docs && !matches!(item.kind, ItemKind::Impl(..)) {
|
||||
if !mod_inner_docs && !matches!(item.kind, ItemKind::Impl(..) | ItemKind::Use(..)) {
|
||||
self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
|
||||
}
|
||||
|
||||
|
@ -2428,6 +2431,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
}
|
||||
|
||||
ItemKind::Use(ref use_tree) => {
|
||||
let maybe_exported = match use_tree.kind {
|
||||
UseTreeKind::Simple(_) | UseTreeKind::Glob => MaybeExported::Ok(item.id),
|
||||
UseTreeKind::Nested(_) => MaybeExported::NestedUse(&item.vis),
|
||||
};
|
||||
self.resolve_doc_links(&item.attrs, maybe_exported);
|
||||
|
||||
self.future_proof_import(use_tree);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue