Skip to content

Commit c6750e4

Browse files
authored
Rollup merge of #95530 - notriddle:notriddle/private-kw-prim, r=jsha
rustdoc: do not show primitives and keywords as private Fixes this: ![image](https://user-images.githubusercontent.com/1593513/161102430-f1f0301e-3e7f-453f-9c0a-bc87a12b893d.png)
2 parents cdf178f + 2983698 commit c6750e4

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
@@ -493,14 +493,17 @@ impl Item {
493493
) -> Item {
494494
trace!("name={:?}, def_id={:?}", name, def_id);
495495

496-
Item {
497-
def_id: def_id.into(),
498-
kind: box kind,
499-
name,
500-
attrs,
501-
visibility: cx.tcx.visibility(def_id).clean(cx),
502-
cfg,
503-
}
496+
// Primitives and Keywords are written in the source code as private modules.
497+
// The modules need to be private so that nobody actually uses them, but the
498+
// keywords and primitives that they are documenting are public.
499+
let visibility = if matches!(&kind, ItemKind::KeywordItem(..) | ItemKind::PrimitiveItem(..))
500+
{
501+
Visibility::Public
502+
} else {
503+
cx.tcx.visibility(def_id).clean(cx)
504+
};
505+
506+
Item { def_id: def_id.into(), kind: box kind, name, attrs, visibility, cfg }
504507
}
505508

506509
/// 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)