Skip to content

Commit 2e99f5f

Browse files
committed
rustdoc: inline compiler-private items into compiler-private crates
Fixes #106421
1 parent 312c9a3 commit 2e99f5f

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

Diff for: src/librustdoc/clean/inline.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_hir::def_id::DefId;
1313
use rustc_hir::Mutability;
1414
use rustc_metadata::creader::{CStore, LoadedMacro};
1515
use rustc_middle::ty::{self, TyCtxt};
16+
use rustc_span::def_id::LOCAL_CRATE;
1617
use rustc_span::hygiene::MacroKind;
1718
use rustc_span::symbol::{kw, sym, Symbol};
1819

@@ -378,6 +379,14 @@ pub(crate) fn build_impl(
378379
let tcx = cx.tcx;
379380
let associated_trait = tcx.impl_trait_ref(did);
380381

382+
// Do not inline compiler-internal items unless we're a compiler-internal crate.
383+
let document_compiler_internal =
384+
if let Some(stab) = tcx.lookup_stability(LOCAL_CRATE.as_def_id()) {
385+
stab.is_unstable() && stab.feature == sym::rustc_private
386+
} else {
387+
false
388+
};
389+
381390
// Only inline impl if the implemented trait is
382391
// reachable in rustdoc generated documentation
383392
if !did.is_local() {
@@ -387,10 +396,8 @@ pub(crate) fn build_impl(
387396
return;
388397
}
389398

390-
if let Some(stab) = tcx.lookup_stability(did) {
391-
if stab.is_unstable() && stab.feature == sym::rustc_private {
392-
return;
393-
}
399+
if !document_compiler_internal && let Some(stab) = tcx.lookup_stability(did) && stab.is_unstable() && stab.feature == sym::rustc_private {
400+
return;
394401
}
395402
}
396403
}
@@ -416,10 +423,8 @@ pub(crate) fn build_impl(
416423
return;
417424
}
418425

419-
if let Some(stab) = tcx.lookup_stability(did) {
420-
if stab.is_unstable() && stab.feature == sym::rustc_private {
421-
return;
422-
}
426+
if !document_compiler_internal && let Some(stab) = tcx.lookup_stability(did) && stab.is_unstable() && stab.feature == sym::rustc_private {
427+
return;
423428
}
424429
}
425430
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-flags: -Zforce-unstable-if-unmarked
2+
#![crate_name="foo"]
3+
pub struct FatalError;
4+
5+
impl FatalError {
6+
pub fn raise(self) -> ! {
7+
loop {}
8+
}
9+
}

Diff for: src/test/rustdoc/issue-106421-not-internal.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// aux-build:issue-106421-force-unstable.rs
2+
// ignore-cross-compile
3+
// This is the version where a non-compiler-internal crate inlines a compiler-internal one.
4+
// In this case, the item shouldn't be documented, because regular users can't get at it.
5+
extern crate foo;
6+
7+
// @!has issue_106421_not_internal/struct.FatalError.html '//*[@id="method.raise"]' 'fn raise'
8+
pub use foo::FatalError;

Diff for: src/test/rustdoc/issue-106421.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// aux-build:issue-106421-force-unstable.rs
2+
// ignore-cross-compile
3+
// compile-flags: -Zforce-unstable-if-unmarked
4+
5+
extern crate foo;
6+
7+
// @has issue_106421/struct.FatalError.html '//*[@id="method.raise"]' 'fn raise'
8+
pub use foo::FatalError;

0 commit comments

Comments
 (0)