Skip to content

Commit ffee30a

Browse files
committed
rustdoc: use stability, instead of features, to decide what to show
To decide if internal items should be inlined in a doc page, check if the crate is itself internal, rather than if it has the rustc_private feature flag. The standard library uses internal items, but is not itself internal and should not show internal items on its docs pages.
1 parent faefc61 commit ffee30a

File tree

4 files changed

+50
-34
lines changed

4 files changed

+50
-34
lines changed

src/librustdoc/clean/inline.rs

+27-28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_hir::Mutability;
1414
use rustc_metadata::creader::{CStore, LoadedMacro};
1515
use rustc_middle::ty::fast_reject::SimplifiedType;
1616
use rustc_middle::ty::{self, TyCtxt};
17+
use rustc_span::def_id::LOCAL_CRATE;
1718
use rustc_span::hygiene::MacroKind;
1819
use rustc_span::symbol::{kw, sym, Symbol};
1920

@@ -444,24 +445,32 @@ pub(crate) fn build_impl(
444445

445446
let associated_trait = tcx.impl_trait_ref(did).map(ty::EarlyBinder::skip_binder);
446447

448+
// Do not inline compiler-internal items unless we're a compiler-internal crate.
449+
let is_compiler_internal = |did| {
450+
if let Some(stab) = tcx.lookup_stability(did) {
451+
stab.is_unstable() && stab.feature == sym::rustc_private
452+
} else {
453+
false
454+
}
455+
};
456+
let document_compiler_internal = is_compiler_internal(LOCAL_CRATE.as_def_id());
457+
let is_directly_public = |cx: &mut DocContext<'_>, did| {
458+
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
459+
return false;
460+
}
461+
if !document_compiler_internal && is_compiler_internal(did) {
462+
return false;
463+
}
464+
true
465+
};
466+
447467
// Only inline impl if the implemented trait is
448468
// reachable in rustdoc generated documentation
449469
if !did.is_local()
450470
&& let Some(traitref) = associated_trait
471+
&& !is_directly_public(cx, traitref.def_id)
451472
{
452-
let did = traitref.def_id;
453-
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
454-
return;
455-
}
456-
457-
if !tcx.features().rustc_private && !cx.render_options.force_unstable_if_unmarked {
458-
if let Some(stab) = tcx.lookup_stability(did)
459-
&& stab.is_unstable()
460-
&& stab.feature == sym::rustc_private
461-
{
462-
return;
463-
}
464-
}
473+
return;
465474
}
466475

467476
let impl_item = match did.as_local() {
@@ -484,21 +493,11 @@ pub(crate) fn build_impl(
484493

485494
// Only inline impl if the implementing type is
486495
// reachable in rustdoc generated documentation
487-
if !did.is_local() {
488-
if let Some(did) = for_.def_id(&cx.cache) {
489-
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
490-
return;
491-
}
492-
493-
if !tcx.features().rustc_private && !cx.render_options.force_unstable_if_unmarked {
494-
if let Some(stab) = tcx.lookup_stability(did)
495-
&& stab.is_unstable()
496-
&& stab.feature == sym::rustc_private
497-
{
498-
return;
499-
}
500-
}
501-
}
496+
if !did.is_local()
497+
&& let Some(did) = for_.def_id(&cx.cache)
498+
&& !is_directly_public(cx, did)
499+
{
500+
return;
502501
}
503502

504503
let document_hidden = cx.render_options.document_hidden;

src/librustdoc/config.rs

-4
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ pub(crate) struct RenderOptions {
285285
pub(crate) no_emit_shared: bool,
286286
/// If `true`, HTML source code pages won't be generated.
287287
pub(crate) html_no_source: bool,
288-
/// Whether `-Zforce-unstable-if-unmarked` unstable option is set
289-
pub(crate) force_unstable_if_unmarked: bool,
290288
}
291289

292290
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -353,7 +351,6 @@ impl Options {
353351

354352
let codegen_options = CodegenOptions::build(early_dcx, matches);
355353
let unstable_opts = UnstableOptions::build(early_dcx, matches);
356-
let force_unstable_if_unmarked = unstable_opts.force_unstable_if_unmarked;
357354

358355
let dcx = new_dcx(error_format, None, diagnostic_width, &unstable_opts);
359356

@@ -790,7 +787,6 @@ impl Options {
790787
call_locations,
791788
no_emit_shared: false,
792789
html_no_source,
793-
force_unstable_if_unmarked,
794790
};
795791
Some((options, render_options))
796792
}
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
//@ aux-build:issue-76736-1.rs
22
//@ aux-build:issue-76736-2.rs
33

4+
// https://github.com/rust-lang/rust/issues/124635
5+
46
#![crate_name = "foo"]
57
#![feature(rustc_private)]
68

79
extern crate issue_76736_1;
810
extern crate issue_76736_2;
911

1012
// @has foo/struct.Foo.html
11-
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
13+
// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
1214
pub struct Foo;
1315

1416
// @has foo/struct.Bar.html
15-
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
17+
// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
1618
pub use issue_76736_2::Bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ aux-build:issue-76736-1.rs
2+
//@ aux-build:issue-76736-2.rs
3+
4+
// https://github.com/rust-lang/rust/issues/124635
5+
6+
#![crate_name = "foo"]
7+
#![feature(rustc_private, staged_api)]
8+
#![unstable(feature = "rustc_private", issue = "none")]
9+
10+
extern crate issue_76736_1;
11+
extern crate issue_76736_2;
12+
13+
// @has foo/struct.Foo.html
14+
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
15+
pub struct Foo;
16+
17+
// @has foo/struct.Bar.html
18+
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
19+
pub use issue_76736_2::Bar;

0 commit comments

Comments
 (0)