Skip to content

Commit 4a1e06b

Browse files
Correctly handle super and ::
1 parent 1d1951b commit 4a1e06b

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/librustdoc/clean/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1497,9 +1497,18 @@ fn first_non_private(
14971497
(cx.tcx.local_parent(hir_id.owner.def_id), leaf.ident)
14981498
}
14991499
// Crate paths are not. We start from the crate root.
1500-
[parent, leaf] if parent.ident.name == kw::Crate => {
1500+
[parent, leaf] if matches!(parent.ident.name, kw::Crate | kw::PathRoot) => {
15011501
(LOCAL_CRATE.as_def_id().as_local()?, leaf.ident)
15021502
}
1503+
[parent, leaf] if parent.ident.name == kw::Super => {
1504+
let parent_mod = cx.tcx.parent_module(hir_id);
1505+
if let Some(super_parent) = cx.tcx.opt_local_parent(parent_mod) {
1506+
(super_parent, leaf.ident)
1507+
} else {
1508+
// If we can't find the parent of the parent, then the parent is already the crate.
1509+
(LOCAL_CRATE.as_def_id().as_local()?, leaf.ident)
1510+
}
1511+
}
15031512
// Absolute paths are not. We start from the parent of the item.
15041513
[.., parent, leaf] => (parent.res.opt_def_id()?.as_local()?, leaf.ident),
15051514
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// edition:2015
2+
3+
#![crate_name = "foo"]
4+
5+
use external::Public as Private;
6+
7+
pub mod external {
8+
pub struct Public;
9+
10+
// @has 'foo/external/fn.make.html'
11+
// @has - '//*[@class="rust item-decl"]/code' 'pub fn make() -> Public'
12+
pub fn make() -> ::Private { super::Private }
13+
}

tests/rustdoc/issue-81141-private-reexport-in-public-api.rs

+10
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,13 @@ pub fn bar14() -> nested::nested2::Whatever3 {
112112
pub fn bar15() -> nested::nested2::Whatever4 {
113113
Whatever
114114
}
115+
116+
use external::Public as Private;
117+
118+
pub mod external {
119+
pub struct Public;
120+
121+
// @has 'foo/external/fn.make.html'
122+
// @has - '//*[@class="rust item-decl"]/code' 'pub fn make() -> Public'
123+
pub fn make() -> super::Private { super::Private }
124+
}

0 commit comments

Comments
 (0)