Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bd7caf4

Browse files
committed
Do not list impl when trait has doc(hidden)
1 parent 3824017 commit bd7caf4

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Support for inlining external documentation into the current AST.
22
3+
use std::collections::VecDeque;
34
use std::iter::once;
45
use std::sync::Arc;
56

@@ -15,7 +16,9 @@ use rustc_span::hygiene::MacroKind;
1516
use rustc_span::symbol::{kw, sym, Symbol};
1617
use rustc_span::Span;
1718

18-
use crate::clean::{self, Attributes, AttributesExt, FakeDefId, GetDefId, ToSource};
19+
use crate::clean::{
20+
self, Attributes, AttributesExt, FakeDefId, GetDefId, NestedAttributesExt, ToSource, Type,
21+
};
1922
use crate::core::DocContext;
2023
use crate::formats::item_type::ItemType;
2124

@@ -420,6 +423,20 @@ crate fn build_impl(
420423
if trait_.def_id() == tcx.lang_items().deref_trait() {
421424
super::build_deref_target_impls(cx, &trait_items, ret);
422425
}
426+
427+
// Return if the trait itself or any types of the generic parameters are doc(hidden).
428+
let mut deque: VecDeque<&Type> = trait_.iter().collect();
429+
while let Some(ty) = deque.pop_back() {
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+
deque.extend(generics);
437+
}
438+
}
439+
423440
if let Some(trait_did) = trait_.def_id() {
424441
record_extern_trait(cx, trait_did);
425442
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[doc(hidden)]
2+
pub enum HiddenType {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Issue #86448: test for cross-crate `doc(hidden)`
2+
#![crate_name = "foo"]
3+
4+
// aux-build:cross-crate-hidden.rs
5+
extern crate cross_crate_hidden;
6+
7+
pub use ::cross_crate_hidden::HiddenType; // 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+
// @!has foo/enum.MyLibType.html '//*[@id="impl-From%3COption%3COption%3COption%3COption%3CHiddenType%3E%3E%3E%3E%3E"]' 'impl From<Option<Option<Option<Option<HiddenType>>>>> for MyLibType'
19+
impl From<Option<Option<Option<Option<HiddenType>>>>> for MyLibType {
20+
fn from(it: Option<Option<Option<Option<HiddenType>>>>) -> MyLibType {
21+
todo!()
22+
}
23+
}

0 commit comments

Comments
 (0)