Skip to content

Commit 3257fba

Browse files
authored
Unrolled build for rust-lang#129414
Rollup merge of rust-lang#129414 - GuillaumeGomez:fix-doc-hidden-crates, r=notriddle Fix extern crates not being hidden with `doc(hidden)` Fixes rust-lang#126796. Only the current crate should never be stripped, any other crate should be strippable. r? ``@notriddle``
2 parents b5723af + 4de29c9 commit 3257fba

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/librustdoc/passes/strip_hidden.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::mem;
44

5-
use rustc_hir::def_id::LocalDefId;
5+
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
66
use rustc_middle::ty::TyCtxt;
77
use rustc_span::symbol::sym;
88

@@ -145,8 +145,9 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
145145
let old = mem::replace(&mut self.update_retained, false);
146146
let ret = self.set_is_in_hidden_item_and_fold(true, i);
147147
self.update_retained = old;
148-
if ret.is_crate() {
149-
// We don't strip the crate, even if it has `#[doc(hidden)]`.
148+
if ret.item_id == clean::ItemId::DefId(CRATE_DEF_ID.into()) {
149+
// We don't strip the current crate, even if it has `#[doc(hidden)]`.
150+
debug!("strip_hidden: Not strippping local crate");
150151
Some(ret)
151152
} else {
152153
Some(strip_item(ret))

tests/rustdoc/doc-hidden-crate.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/126796>.
2+
// `doc(hidden)` should still be able to hide extern crates, only the local crates
3+
// cannot be hidden because we still need to generate its `index.html` file.
4+
5+
#![crate_name = "foo"]
6+
#![doc(hidden)]
7+
8+
//@ has 'foo/index.html'
9+
// First we check that the page contains the crate name (`foo`).
10+
//@ has - '//*' 'foo'
11+
// But doesn't contain any of the other items.
12+
//@ !has - '//*' 'other'
13+
//@ !has - '//*' 'marker'
14+
//@ !has - '//*' 'PhantomData'
15+
16+
#[doc(inline)]
17+
pub use std as other;
18+
19+
#[doc(inline)]
20+
pub use std::marker;
21+
22+
#[doc(inline)]
23+
pub use std::marker::PhantomData;
24+
25+
//@ !has - '//*' 'myself'
26+
#[doc(inline)]
27+
pub use crate as myself;

0 commit comments

Comments
 (0)