Skip to content

Commit 356d8ad

Browse files
committed
Auto merge of #76571 - lzutao:rustdoc-private-traits, r=jyn514
Ignore rustc_private items from std docs By ignoring rustc_private items for non local impl block, this may fix #74672 and fix #75588 . This might suppress #76529 if it is simple enough for backport.
2 parents b5f55b7 + c743fc4 commit 356d8ad

File tree

5 files changed

+66
-9
lines changed

5 files changed

+66
-9
lines changed

src/librustdoc/clean/inline.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,13 @@ pub fn build_impl(
337337
// reachable in rustdoc generated documentation
338338
if !did.is_local() {
339339
if let Some(traitref) = associated_trait {
340-
if !cx.renderinfo.borrow().access_levels.is_public(traitref.def_id) {
340+
let did = traitref.def_id;
341+
if !cx.renderinfo.borrow().access_levels.is_public(did) {
341342
return;
342343
}
343-
}
344344

345-
// Skip foreign unstable traits from lists of trait implementations and
346-
// such. This helps prevent dependencies of the standard library, for
347-
// example, from getting documented as "traits `u32` implements" which
348-
// isn't really too helpful.
349-
if let Some(trait_did) = associated_trait {
350-
if let Some(stab) = cx.tcx.lookup_stability(trait_did.def_id) {
351-
if stab.level.is_unstable() {
345+
if let Some(stab) = tcx.lookup_stability(did) {
346+
if stab.level.is_unstable() && stab.feature == sym::rustc_private {
352347
return;
353348
}
354349
}
@@ -372,6 +367,12 @@ pub fn build_impl(
372367
if !cx.renderinfo.borrow().access_levels.is_public(did) {
373368
return;
374369
}
370+
371+
if let Some(stab) = tcx.lookup_stability(did) {
372+
if stab.level.is_unstable() && stab.feature == sym::rustc_private {
373+
return;
374+
}
375+
}
375376
}
376377
}
377378

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// aux-build:realcore.rs
2+
3+
#![crate_name = "real_gimli"]
4+
#![feature(staged_api, extremely_unstable)]
5+
#![unstable(feature = "rustc_private", issue = "none")]
6+
7+
extern crate realcore;
8+
9+
#[unstable(feature = "rustc_private", issue = "none")]
10+
pub struct EndianSlice;
11+
12+
#[unstable(feature = "rustc_private", issue = "none")]
13+
impl realcore::Deref for EndianSlice {}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![crate_name = "realcore"]
2+
#![feature(staged_api)]
3+
#![unstable(feature = "extremely_unstable", issue = "none")]
4+
5+
#[unstable(feature = "extremely_unstable_foo", issue = "none")]
6+
pub struct Foo {}
7+
8+
#[unstable(feature = "extremely_unstable_foo", issue = "none")]
9+
pub trait Join {}
10+
11+
#[unstable(feature = "extremely_unstable_foo", issue = "none")]
12+
impl Join for Foo {}
13+
14+
#[stable(feature = "faked_deref", since = "1.47.0")]
15+
pub trait Deref {}

src/test/rustdoc/issue-75588.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ignore-tidy-linelength
2+
// aux-build:realcore.rs
3+
// aux-build:real_gimli.rs
4+
5+
// Ensure unstably exported traits have their Implementors sections.
6+
7+
#![crate_name = "foo"]
8+
#![feature(extremely_unstable_foo)]
9+
10+
extern crate realcore;
11+
extern crate real_gimli;
12+
13+
// issue #74672
14+
// @!has foo/trait.Deref.html '//*[@id="impl-Deref-for-EndianSlice"]//code' 'impl Deref for EndianSlice'
15+
pub use realcore::Deref;
16+
17+
// @has foo/trait.Join.html '//*[@id="impl-Join-for-Foo"]//code' 'impl Join for Foo'
18+
pub use realcore::Join;

src/tools/linkchecker/main.rs

+10
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ fn is_exception(file: &Path, link: &str) -> bool {
142142
if let Some(entry) = LINKCHECK_EXCEPTIONS.iter().find(|&(f, _)| file.ends_with(f)) {
143143
entry.1.contains(&link)
144144
} else {
145+
// FIXME(#63351): Concat trait in alloc/slice reexported in primitive page
146+
//
147+
// NOTE: This cannot be added to `LINKCHECK_EXCEPTIONS` because the resolved path
148+
// calculated in `check` function is outside `build/<triple>/doc` dir.
149+
// So the `strip_prefix` method just returns the old absolute broken path.
150+
if file.ends_with("std/primitive.slice.html") {
151+
if link.ends_with("primitive.slice.html") {
152+
return true;
153+
}
154+
}
145155
false
146156
}
147157
}

0 commit comments

Comments
 (0)