Skip to content

Commit 2983698

Browse files
committed
rustdoc: do not show primitives and keywords as private
1 parent 0331491 commit 2983698

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/librustdoc/clean/types.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,17 @@ impl Item {
471471
) -> Item {
472472
trace!("name={:?}, def_id={:?}", name, def_id);
473473

474-
Item {
475-
def_id: def_id.into(),
476-
kind: box kind,
477-
name,
478-
attrs,
479-
visibility: cx.tcx.visibility(def_id).clean(cx),
480-
cfg,
481-
}
474+
// Primitives and Keywords are written in the source code as private modules.
475+
// The modules need to be private so that nobody actually uses them, but the
476+
// keywords and primitives that they are documenting are public.
477+
let visibility = if matches!(&kind, ItemKind::KeywordItem(..) | ItemKind::PrimitiveItem(..))
478+
{
479+
Visibility::Public
480+
} else {
481+
cx.tcx.visibility(def_id).clean(cx)
482+
};
483+
484+
Item { def_id: def_id.into(), kind: box kind, name, attrs, visibility, cfg }
482485
}
483486

484487
/// Finds all `doc` attributes as NameValues and returns their corresponding values, joined

src/test/rustdoc/keyword.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// @has foo/index.html '//a/@href' '../foo/index.html'
1313
// @!has foo/foo/index.html
1414
// @!has-dir foo/foo
15+
// @!has foo/index.html '//span' '🔒'
1516
#[doc(keyword = "match")]
1617
/// this is a test!
1718
mod foo{}

src/test/rustdoc/primitive.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![crate_name = "foo"]
2+
3+
#![feature(rustdoc_internals)]
4+
5+
// @has foo/index.html '//h2[@id="primitives"]' 'Primitive Types'
6+
// @has foo/index.html '//a[@href="primitive.i32.html"]' 'i32'
7+
// @has foo/index.html '//div[@class="sidebar-elems"]//li/a' 'Primitive Types'
8+
// @has foo/index.html '//div[@class="sidebar-elems"]//li/a/@href' '#primitives'
9+
// @has foo/primitive.i32.html '//a[@class="primitive"]' 'i32'
10+
// @has foo/primitive.i32.html '//span[@class="in-band"]' 'Primitive Type i32'
11+
// @has foo/primitive.i32.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
12+
// @has foo/index.html '//a/@href' '../foo/index.html'
13+
// @!has foo/index.html '//span' '🔒'
14+
#[doc(primitive = "i32")]
15+
/// this is a test!
16+
mod i32{}
17+
18+
// @has foo/primitive.bool.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'hello'
19+
#[doc(primitive = "bool")]
20+
/// hello
21+
mod bool {}

0 commit comments

Comments
 (0)