Skip to content

Commit

Permalink
Correctly handle super and ::
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jul 7, 2023
1 parent 1d1951b commit 4a1e06b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,9 +1497,18 @@ fn first_non_private(
(cx.tcx.local_parent(hir_id.owner.def_id), leaf.ident)
}
// Crate paths are not. We start from the crate root.
[parent, leaf] if parent.ident.name == kw::Crate => {
[parent, leaf] if matches!(parent.ident.name, kw::Crate | kw::PathRoot) => {
(LOCAL_CRATE.as_def_id().as_local()?, leaf.ident)
}
[parent, leaf] if parent.ident.name == kw::Super => {
let parent_mod = cx.tcx.parent_module(hir_id);
if let Some(super_parent) = cx.tcx.opt_local_parent(parent_mod) {
(super_parent, leaf.ident)
} else {
// If we can't find the parent of the parent, then the parent is already the crate.
(LOCAL_CRATE.as_def_id().as_local()?, leaf.ident)
}
}
// Absolute paths are not. We start from the parent of the item.
[.., parent, leaf] => (parent.res.opt_def_id()?.as_local()?, leaf.ident),
};
Expand Down
13 changes: 13 additions & 0 deletions tests/rustdoc/issue-81141-private-reexport-in-public-api-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// edition:2015

#![crate_name = "foo"]

use external::Public as Private;

pub mod external {
pub struct Public;

// @has 'foo/external/fn.make.html'
// @has - '//*[@class="rust item-decl"]/code' 'pub fn make() -> Public'
pub fn make() -> ::Private { super::Private }
}
10 changes: 10 additions & 0 deletions tests/rustdoc/issue-81141-private-reexport-in-public-api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,13 @@ pub fn bar14() -> nested::nested2::Whatever3 {
pub fn bar15() -> nested::nested2::Whatever4 {
Whatever
}

use external::Public as Private;

pub mod external {
pub struct Public;

// @has 'foo/external/fn.make.html'
// @has - '//*[@class="rust item-decl"]/code' 'pub fn make() -> Public'
pub fn make() -> super::Private { super::Private }
}

0 comments on commit 4a1e06b

Please sign in to comment.