Skip to content

Commit 724bcec

Browse files
committed
rustdoc: Hide impls for #[doc(hidden)] traits
Closes #14585
1 parent 5135547 commit 724bcec

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/libcore/fmt/num.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use iter::Iterator; // NOTE(stage0): Remove after snapshot.
2626
use option::{Some, None}; // NOTE(stage0): Remove after snapshot.
2727

2828
/// A type that represents a specific radix
29+
#[doc(hidden)]
2930
trait GenericRadix {
3031
/// The number of digits.
3132
fn base(&self) -> u8;

src/librustdoc/clean/inline.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,17 @@ fn build_impl(cx: &core::DocContext,
278278
}
279279

280280
let associated_trait = csearch::get_impl_trait(tcx, did);
281+
// If this is an impl for a #[doc(hidden)] trait, be sure to not inline it.
282+
match associated_trait {
283+
Some(ref t) => {
284+
let trait_attrs = load_attrs(tcx, t.def_id);
285+
if trait_attrs.iter().any(|a| is_doc_hidden(a)) {
286+
return None
287+
}
288+
}
289+
None => {}
290+
}
291+
281292
let attrs = load_attrs(tcx, did);
282293
let ty = ty::lookup_item_type(tcx, did);
283294
let methods = csearch::get_impl_methods(&tcx.sess.cstore,
@@ -302,7 +313,7 @@ fn build_impl(cx: &core::DocContext,
302313
};
303314
Some(item)
304315
}).collect();
305-
Some(clean::Item {
316+
return Some(clean::Item {
306317
inner: clean::ImplItem(clean::Impl {
307318
derived: clean::detect_derived(attrs.as_slice()),
308319
trait_: associated_trait.clean().map(|bound| {
@@ -321,7 +332,21 @@ fn build_impl(cx: &core::DocContext,
321332
visibility: Some(ast::Inherited),
322333
stability: stability::lookup(tcx, did).clean(),
323334
def_id: did,
324-
})
335+
});
336+
337+
fn is_doc_hidden(a: &clean::Attribute) -> bool {
338+
match *a {
339+
clean::List(ref name, ref inner) if name.as_slice() == "doc" => {
340+
inner.iter().any(|a| {
341+
match *a {
342+
clean::Word(ref s) => s.as_slice() == "hidden",
343+
_ => false,
344+
}
345+
})
346+
}
347+
_ => false
348+
}
349+
}
325350
}
326351

327352
fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,

0 commit comments

Comments
 (0)