Auto merge of #44026 - QuietMisdreavus:trimmed-std, r=steveklabnik
hide internal types/traits from std docs via new #[doc(masked)] attribute Fixes #43701 (hopefully for good this time) This PR introduces a new parameter to the `#[doc]` attribute that rustdoc looks for on `extern crate` statements. When it sees `#[doc(masked)]` on such a statement, it hides traits and types from that crate from appearing in either the "Trait Implementations" section of many type pages, or the "Implementors" section of trait pages. This is then applied to the `libc`/`rand`/`compiler_builtins` imports in libstd to prevent those crates from creating broken links in the std docs. Like in #43348, this also introduces a feature gate, `doc_masked`, that controls the use of this parameter. To view the std docs generated with this change, head to https://tonberry.quietmisdreavus.net/std-43701/std/index.html.
This commit is contained in:
@@ -266,6 +266,7 @@ pub struct Cache {
|
||||
deref_trait_did: Option<DefId>,
|
||||
deref_mut_trait_did: Option<DefId>,
|
||||
owned_box_did: Option<DefId>,
|
||||
masked_crates: FxHashSet<CrateNum>,
|
||||
|
||||
// In rare case where a structure is defined in one module but implemented
|
||||
// in another, if the implementing module is parsed before defining module,
|
||||
@@ -538,6 +539,7 @@ pub fn run(mut krate: clean::Crate,
|
||||
deref_trait_did,
|
||||
deref_mut_trait_did,
|
||||
owned_box_did,
|
||||
masked_crates: mem::replace(&mut krate.masked_crates, FxHashSet()),
|
||||
typarams: external_typarams,
|
||||
};
|
||||
|
||||
@@ -1114,12 +1116,16 @@ impl DocFolder for Cache {
|
||||
|
||||
// Collect all the implementors of traits.
|
||||
if let clean::ImplItem(ref i) = item.inner {
|
||||
if let Some(did) = i.trait_.def_id() {
|
||||
self.implementors.entry(did).or_insert(vec![]).push(Implementor {
|
||||
def_id: item.def_id,
|
||||
stability: item.stability.clone(),
|
||||
impl_: i.clone(),
|
||||
});
|
||||
if !self.masked_crates.contains(&item.def_id.krate) {
|
||||
if let Some(did) = i.trait_.def_id() {
|
||||
if i.for_.def_id().map_or(true, |d| !self.masked_crates.contains(&d.krate)) {
|
||||
self.implementors.entry(did).or_insert(vec![]).push(Implementor {
|
||||
def_id: item.def_id,
|
||||
stability: item.stability.clone(),
|
||||
impl_: i.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1281,18 +1287,24 @@ impl DocFolder for Cache {
|
||||
// primitive rather than always to a struct/enum.
|
||||
// Note: matching twice to restrict the lifetime of the `i` borrow.
|
||||
let did = if let clean::Item { inner: clean::ImplItem(ref i), .. } = item {
|
||||
match i.for_ {
|
||||
clean::ResolvedPath { did, .. } |
|
||||
clean::BorrowedRef {
|
||||
type_: box clean::ResolvedPath { did, .. }, ..
|
||||
} => {
|
||||
Some(did)
|
||||
}
|
||||
ref t => {
|
||||
t.primitive_type().and_then(|t| {
|
||||
self.primitive_locations.get(&t).cloned()
|
||||
})
|
||||
let masked_trait = i.trait_.def_id().map_or(false,
|
||||
|d| self.masked_crates.contains(&d.krate));
|
||||
if !masked_trait {
|
||||
match i.for_ {
|
||||
clean::ResolvedPath { did, .. } |
|
||||
clean::BorrowedRef {
|
||||
type_: box clean::ResolvedPath { did, .. }, ..
|
||||
} => {
|
||||
Some(did)
|
||||
}
|
||||
ref t => {
|
||||
t.primitive_type().and_then(|t| {
|
||||
self.primitive_locations.get(&t).cloned()
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
unreachable!()
|
||||
|
||||
Reference in New Issue
Block a user