Skip to content

Commit

Permalink
Rollup merge of #129414 - GuillaumeGomez:fix-doc-hidden-crates, r=not…
Browse files Browse the repository at this point in the history
…riddle

Fix extern crates not being hidden with `doc(hidden)`

Fixes #126796.

Only the current crate should never be stripped, any other crate should be strippable.

r? ``@notriddle``
  • Loading branch information
matthiaskrgr authored Aug 23, 2024
2 parents 79d3666 + 4de29c9 commit 65af38a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/librustdoc/passes/strip_hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::mem;

use rustc_hir::def_id::LocalDefId;
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::sym;

Expand Down Expand Up @@ -145,8 +145,9 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
let old = mem::replace(&mut self.update_retained, false);
let ret = self.set_is_in_hidden_item_and_fold(true, i);
self.update_retained = old;
if ret.is_crate() {
// We don't strip the crate, even if it has `#[doc(hidden)]`.
if ret.item_id == clean::ItemId::DefId(CRATE_DEF_ID.into()) {
// We don't strip the current crate, even if it has `#[doc(hidden)]`.
debug!("strip_hidden: Not strippping local crate");
Some(ret)
} else {
Some(strip_item(ret))
Expand Down
27 changes: 27 additions & 0 deletions tests/rustdoc/doc-hidden-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Regression test for <https://github.com/rust-lang/rust/issues/126796>.
// `doc(hidden)` should still be able to hide extern crates, only the local crates
// cannot be hidden because we still need to generate its `index.html` file.

#![crate_name = "foo"]
#![doc(hidden)]

//@ has 'foo/index.html'
// First we check that the page contains the crate name (`foo`).
//@ has - '//*' 'foo'
// But doesn't contain any of the other items.
//@ !has - '//*' 'other'
//@ !has - '//*' 'marker'
//@ !has - '//*' 'PhantomData'

#[doc(inline)]
pub use std as other;

#[doc(inline)]
pub use std::marker;

#[doc(inline)]
pub use std::marker::PhantomData;

//@ !has - '//*' 'myself'
#[doc(inline)]
pub use crate as myself;

0 comments on commit 65af38a

Please sign in to comment.