Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: inline compiler-private items into compiler-private crates #106424

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
notriddle marked this conversation as resolved.
Show resolved Hide resolved
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;