Skip to content

Commit

Permalink
rustdoc: inline compiler-private items into compiler-private crates
Browse files Browse the repository at this point in the history
Fixes #106421
  • Loading branch information
notriddle committed Jan 3, 2023
1 parent 312c9a3 commit 2e99f5f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rustc_hir::def_id::DefId;
use rustc_hir::Mutability;
use rustc_metadata::creader::{CStore, LoadedMacro};
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Symbol};

Expand Down Expand Up @@ -378,6 +379,14 @@ pub(crate) fn build_impl(
let tcx = cx.tcx;
let associated_trait = tcx.impl_trait_ref(did);

// Do not inline compiler-internal items unless we're a compiler-internal crate.
let document_compiler_internal =
if let Some(stab) = tcx.lookup_stability(LOCAL_CRATE.as_def_id()) {
stab.is_unstable() && stab.feature == sym::rustc_private
} else {
false
};

// Only inline impl if the implemented trait is
// reachable in rustdoc generated documentation
if !did.is_local() {
Expand All @@ -387,10 +396,8 @@ pub(crate) fn build_impl(
return;
}

if let Some(stab) = tcx.lookup_stability(did) {
if stab.is_unstable() && stab.feature == sym::rustc_private {
return;
}
if !document_compiler_internal && let Some(stab) = tcx.lookup_stability(did) && stab.is_unstable() && stab.feature == sym::rustc_private {
return;
}
}
}
Expand All @@ -416,10 +423,8 @@ pub(crate) fn build_impl(
return;
}

if let Some(stab) = tcx.lookup_stability(did) {
if stab.is_unstable() && stab.feature == sym::rustc_private {
return;
}
if !document_compiler_internal && let Some(stab) = tcx.lookup_stability(did) && stab.is_unstable() && stab.feature == sym::rustc_private {
return;
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/rustdoc/auxiliary/issue-106421-force-unstable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// compile-flags: -Zforce-unstable-if-unmarked
#![crate_name="foo"]
pub struct FatalError;

impl FatalError {
pub fn raise(self) -> ! {
loop {}
}
}
8 changes: 8 additions & 0 deletions src/test/rustdoc/issue-106421-not-internal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// aux-build:issue-106421-force-unstable.rs
// ignore-cross-compile
// This is the version where a non-compiler-internal crate inlines a compiler-internal one.
// In this case, the item shouldn't be documented, because regular users can't get at it.
extern crate foo;

// @!has issue_106421_not_internal/struct.FatalError.html '//*[@id="method.raise"]' 'fn raise'
pub use foo::FatalError;
8 changes: 8 additions & 0 deletions src/test/rustdoc/issue-106421.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// aux-build:issue-106421-force-unstable.rs
// ignore-cross-compile
// compile-flags: -Zforce-unstable-if-unmarked

extern crate foo;

// @has issue_106421/struct.FatalError.html '//*[@id="method.raise"]' 'fn raise'
pub use foo::FatalError;

0 comments on commit 2e99f5f

Please sign in to comment.