Skip to content

Commit 2940eb5

Browse files
authored
Auto merge of #34232 - ollie27:rustdoc_inline, r=alexcrichton
rustdoc: Don't inline #[doc(hidden)] pub use Currently if a `#[doc(hidden)] pub use` item is inlined the `hidden` attribute is ignored so the item can appear in the docs. By never inlining such imports, they can be stripped. An example in `std` is [`__OsLocalKeyInner`](https://doc.rust-lang.org/nightly/std/thread/struct.__OsLocalKeyInner.html) which clearly should not be documented.
2 parents 1af8f3e + a7c4674 commit 2940eb5

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

src/librustdoc/clean/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2389,9 +2389,11 @@ impl Clean<Vec<Item>> for doctree::Import {
23892389
// We consider inlining the documentation of `pub use` statements, but we
23902390
// forcefully don't inline if this is not public or if the
23912391
// #[doc(no_inline)] attribute is present.
2392+
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
23922393
let denied = self.vis != hir::Public || self.attrs.iter().any(|a| {
23932394
&a.name()[..] == "doc" && match a.meta_item_list() {
2394-
Some(l) => attr::contains_name(l, "no_inline"),
2395+
Some(l) => attr::contains_name(l, "no_inline") ||
2396+
attr::contains_name(l, "hidden"),
23952397
None => false,
23962398
}
23972399
});

src/librustdoc/visit_ast.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
245245
let def_did = def.def_id();
246246

247247
let use_attrs = tcx.map.attrs(id).clean(self.cx);
248-
let is_no_inline = use_attrs.list("doc").has_word("no_inline");
248+
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
249+
let is_no_inline = use_attrs.list("doc").has_word("no_inline") ||
250+
use_attrs.list("doc").has_word("hidden");
249251

250252
// For cross-crate impl inlining we need to know whether items are
251253
// reachable in documentation - a previously nonreachable item can be
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:rustdoc-hidden.rs
12+
// build-aux-docs
13+
// ignore-cross-compile
14+
15+
extern crate rustdoc_hidden;
16+
17+
// @has hidden_use/index.html
18+
// @!has - 'rustdoc_hidden'
19+
// @!has - 'Bar'
20+
// @!has hidden_use/struct.Bar.html
21+
#[doc(hidden)]
22+
pub use rustdoc_hidden::Bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
mod private {
12+
pub struct Foo {}
13+
}
14+
15+
// @has hidden_use/index.html
16+
// @!has - 'private'
17+
// @!has - 'Foo'
18+
// @!has hidden_use/struct.Foo.html
19+
#[doc(hidden)]
20+
pub use private::Foo;

0 commit comments

Comments
 (0)