Skip to content

Commit 6be1732

Browse files
authored
Rollup merge of #86513 - fee1-dead:cross-crate-doc-hidden, r=danielhenrymantilla
Rustdoc: Do not list impl when trait has doc(hidden) Fixes #86448.
2 parents e01a720 + 9a63434 commit 6be1732

File tree

4 files changed

+94
-1
lines changed

4 files changed

+94
-1
lines changed

src/librustdoc/clean/inline.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use rustc_span::hygiene::MacroKind;
1515
use rustc_span::symbol::{kw, sym, Symbol};
1616
use rustc_span::Span;
1717

18-
use crate::clean::{self, Attributes, AttributesExt, FakeDefId, GetDefId, ToSource};
18+
use crate::clean::{
19+
self, Attributes, AttributesExt, FakeDefId, GetDefId, NestedAttributesExt, ToSource, Type,
20+
};
1921
use crate::core::DocContext;
2022
use crate::formats::item_type::ItemType;
2123

@@ -420,6 +422,21 @@ crate fn build_impl(
420422
if trait_.def_id() == tcx.lang_items().deref_trait() {
421423
super::build_deref_target_impls(cx, &trait_items, ret);
422424
}
425+
426+
// Return if the trait itself or any types of the generic parameters are doc(hidden).
427+
let mut stack: Vec<&Type> = trait_.iter().collect();
428+
stack.push(&for_);
429+
while let Some(ty) = stack.pop() {
430+
if let Some(did) = ty.def_id() {
431+
if cx.tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden) {
432+
return;
433+
}
434+
}
435+
if let Some(generics) = ty.generics() {
436+
stack.extend(generics);
437+
}
438+
}
439+
423440
if let Some(trait_did) = trait_.def_id() {
424441
record_extern_trait(cx, trait_did);
425442
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[doc(hidden)]
2+
pub enum HiddenType {}
3+
4+
#[doc(hidden)]
5+
pub trait HiddenTrait {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Issue #86448: test for cross-crate `doc(hidden)`
2+
#![crate_name = "foo"]
3+
4+
// aux-build:cross-crate-hidden-impl-parameter.rs
5+
extern crate cross_crate_hidden_impl_parameter;
6+
7+
pub use ::cross_crate_hidden_impl_parameter::{HiddenType, HiddenTrait}; // OK, not re-exported
8+
9+
pub enum MyLibType {}
10+
11+
// @!has foo/enum.MyLibType.html '//*[@id="impl-From%3CHiddenType%3E"]' 'impl From<HiddenType> for MyLibType'
12+
impl From<HiddenType> for MyLibType {
13+
fn from(it: HiddenType) -> MyLibType {
14+
match it {}
15+
}
16+
}
17+
18+
pub struct T<T>(T);
19+
20+
// @!has foo/enum.MyLibType.html '//*[@id="impl-From%3CT%3CT%3CT%3CT%3CHiddenType%3E%3E%3E%3E%3E"]' 'impl From<T<T<T<T<HiddenType>>>>> for MyLibType'
21+
impl From<T<T<T<T<HiddenType>>>>> for MyLibType {
22+
fn from(it: T<T<T<T<HiddenType>>>>) -> MyLibType {
23+
todo!()
24+
}
25+
}
26+
27+
// @!has foo/enum.MyLibType.html '//*[@id="impl-HiddenTrait"]' 'impl HiddenTrait for MyLibType'
28+
impl HiddenTrait for MyLibType {}
29+
30+
// @!has foo/struct.T.html '//*[@id="impl-From%3CMyLibType%3E"]' 'impl From<MyLibType> for T<T<T<T<HiddenType>>>>'
31+
impl From<MyLibType> for T<T<T<T<HiddenType>>>> {
32+
fn from(it: MyLibType) -> T<T<T<T<HiddenType>>>> {
33+
match it {}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// test for `doc(hidden)` with impl parameters in the same crate.
2+
#![crate_name = "foo"]
3+
4+
#[doc(hidden)]
5+
pub enum HiddenType {}
6+
7+
#[doc(hidden)]
8+
pub trait HiddenTrait {}
9+
10+
pub enum MyLibType {}
11+
12+
// @!has foo/enum.MyLibType.html '//*[@id="impl-From%3CHiddenType%3E"]' 'impl From<HiddenType> for MyLibType'
13+
impl From<HiddenType> for MyLibType {
14+
fn from(it: HiddenType) -> MyLibType {
15+
match it {}
16+
}
17+
}
18+
19+
pub struct T<T>(T);
20+
21+
// @!has foo/enum.MyLibType.html '//*[@id="impl-From%3CT%3CT%3CT%3CT%3CHiddenType%3E%3E%3E%3E%3E"]' 'impl From<T<T<T<T<HiddenType>>>>> for MyLibType'
22+
impl From<T<T<T<T<HiddenType>>>>> for MyLibType {
23+
fn from(it: T<T<T<T<HiddenType>>>>) -> MyLibType {
24+
todo!()
25+
}
26+
}
27+
28+
// @!has foo/enum.MyLibType.html '//*[@id="impl-HiddenTrait"]' 'impl HiddenTrait for MyLibType'
29+
impl HiddenTrait for MyLibType {}
30+
31+
// @!has foo/struct.T.html '//*[@id="impl-From%3CMyLibType%3E"]' 'impl From<MyLibType> for T<T<T<T<HiddenType>>>>'
32+
impl From<MyLibType> for T<T<T<T<HiddenType>>>> {
33+
fn from(it: MyLibType) -> T<T<T<T<HiddenType>>>> {
34+
match it {}
35+
}
36+
}

0 commit comments

Comments
 (0)