mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-19 10:24:16 +00:00
Rollup merge of #86513 - fee1-dead:cross-crate-doc-hidden, r=danielhenrymantilla
Rustdoc: Do not list impl when trait has doc(hidden) Fixes #86448.
This commit is contained in:
commit
6be1732e69
@ -15,7 +15,9 @@ use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
||||
use crate::clean::{self, Attributes, AttributesExt, FakeDefId, GetDefId, ToSource};
|
||||
use crate::clean::{
|
||||
self, Attributes, AttributesExt, FakeDefId, GetDefId, NestedAttributesExt, ToSource, Type,
|
||||
};
|
||||
use crate::core::DocContext;
|
||||
use crate::formats::item_type::ItemType;
|
||||
|
||||
@ -420,6 +422,21 @@ crate fn build_impl(
|
||||
if trait_.def_id() == tcx.lang_items().deref_trait() {
|
||||
super::build_deref_target_impls(cx, &trait_items, ret);
|
||||
}
|
||||
|
||||
// Return if the trait itself or any types of the generic parameters are doc(hidden).
|
||||
let mut stack: Vec<&Type> = trait_.iter().collect();
|
||||
stack.push(&for_);
|
||||
while let Some(ty) = stack.pop() {
|
||||
if let Some(did) = ty.def_id() {
|
||||
if cx.tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Some(generics) = ty.generics() {
|
||||
stack.extend(generics);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(trait_did) = trait_.def_id() {
|
||||
record_extern_trait(cx, trait_did);
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
#[doc(hidden)]
|
||||
pub enum HiddenType {}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub trait HiddenTrait {}
|
35
src/test/rustdoc/cross-crate-hidden-impl-parameter.rs
Normal file
35
src/test/rustdoc/cross-crate-hidden-impl-parameter.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// Issue #86448: test for cross-crate `doc(hidden)`
|
||||
#![crate_name = "foo"]
|
||||
|
||||
// aux-build:cross-crate-hidden-impl-parameter.rs
|
||||
extern crate cross_crate_hidden_impl_parameter;
|
||||
|
||||
pub use ::cross_crate_hidden_impl_parameter::{HiddenType, HiddenTrait}; // OK, not re-exported
|
||||
|
||||
pub enum MyLibType {}
|
||||
|
||||
// @!has foo/enum.MyLibType.html '//*[@id="impl-From%3CHiddenType%3E"]' 'impl From<HiddenType> for MyLibType'
|
||||
impl From<HiddenType> for MyLibType {
|
||||
fn from(it: HiddenType) -> MyLibType {
|
||||
match it {}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct T<T>(T);
|
||||
|
||||
// @!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'
|
||||
impl From<T<T<T<T<HiddenType>>>>> for MyLibType {
|
||||
fn from(it: T<T<T<T<HiddenType>>>>) -> MyLibType {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// @!has foo/enum.MyLibType.html '//*[@id="impl-HiddenTrait"]' 'impl HiddenTrait for MyLibType'
|
||||
impl HiddenTrait for MyLibType {}
|
||||
|
||||
// @!has foo/struct.T.html '//*[@id="impl-From%3CMyLibType%3E"]' 'impl From<MyLibType> for T<T<T<T<HiddenType>>>>'
|
||||
impl From<MyLibType> for T<T<T<T<HiddenType>>>> {
|
||||
fn from(it: MyLibType) -> T<T<T<T<HiddenType>>>> {
|
||||
match it {}
|
||||
}
|
||||
}
|
36
src/test/rustdoc/same-crate-hidden-impl-parameter.rs
Normal file
36
src/test/rustdoc/same-crate-hidden-impl-parameter.rs
Normal file
@ -0,0 +1,36 @@
|
||||
// test for `doc(hidden)` with impl parameters in the same crate.
|
||||
#![crate_name = "foo"]
|
||||
|
||||
#[doc(hidden)]
|
||||
pub enum HiddenType {}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub trait HiddenTrait {}
|
||||
|
||||
pub enum MyLibType {}
|
||||
|
||||
// @!has foo/enum.MyLibType.html '//*[@id="impl-From%3CHiddenType%3E"]' 'impl From<HiddenType> for MyLibType'
|
||||
impl From<HiddenType> for MyLibType {
|
||||
fn from(it: HiddenType) -> MyLibType {
|
||||
match it {}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct T<T>(T);
|
||||
|
||||
// @!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'
|
||||
impl From<T<T<T<T<HiddenType>>>>> for MyLibType {
|
||||
fn from(it: T<T<T<T<HiddenType>>>>) -> MyLibType {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// @!has foo/enum.MyLibType.html '//*[@id="impl-HiddenTrait"]' 'impl HiddenTrait for MyLibType'
|
||||
impl HiddenTrait for MyLibType {}
|
||||
|
||||
// @!has foo/struct.T.html '//*[@id="impl-From%3CMyLibType%3E"]' 'impl From<MyLibType> for T<T<T<T<HiddenType>>>>'
|
||||
impl From<MyLibType> for T<T<T<T<HiddenType>>>> {
|
||||
fn from(it: MyLibType) -> T<T<T<T<HiddenType>>>> {
|
||||
match it {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user