* Fix some typo

* Improve documentation
* Add a test to ensure that spotlighted traits from dependencies are taken into account as expected
This commit is contained in:
Guillaume Gomez 2021-02-14 14:47:55 +01:00
parent b5c8eea55d
commit 3c59e64abf
3 changed files with 31 additions and 10 deletions

View file

@ -521,14 +521,15 @@ crate fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<De
} }
} }
/// Checks that one attribute is `doc`. For example: /// Checks for the existence of `hidden` in the attribute below if `flag` is `sym::hidden`:
/// ///
/// ```text /// ```
/// #[doc(spotlight)] /// #[doc(hidden)]
/// pub fn foo() {}
/// ``` /// ```
/// ///
/// This function has to exists because it runs on `hir::Attributes` whereas the other runs on /// This function exists because it runs on `hir::Attributes` whereas the other is a
/// `clean::Attributes`. /// `clean::Attributes` method.
crate fn has_doc_flag(attrs: Attributes<'_>, flag: Symbol) -> bool { crate fn has_doc_flag(attrs: Attributes<'_>, flag: Symbol) -> bool {
attrs.iter().any(|attr| { attrs.iter().any(|attr| {
attr.has_name(sym::doc) attr.has_name(sym::doc)

View file

@ -245,16 +245,12 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
} }
} }
let tcx = self.tcx;
// Propagate a trait method's documentation to all implementors of the // Propagate a trait method's documentation to all implementors of the
// trait. // trait.
if let clean::TraitItem(ref t) = *item.kind { if let clean::TraitItem(ref t) = *item.kind {
self.cache.traits.entry(item.def_id).or_insert_with(|| clean::TraitWithExtraInfo { self.cache.traits.entry(item.def_id).or_insert_with(|| clean::TraitWithExtraInfo {
trait_: t.clone(), trait_: t.clone(),
is_spotlight: clean::utils::has_doc_flag( is_spotlight: item.attrs.has_doc_flag(sym::spotlight),
tcx.get_attrs(item.def_id),
sym::spotlight,
),
}); });
} }

View file

@ -0,0 +1,24 @@
#![crate_name = "foo"]
use std::iter::Iterator;
// @has foo/struct.Odd.html
// @has - '//h4[@id="method.new"]//span[@class="notable-traits"]//code/span' 'impl Iterator for Odd'
pub struct Odd {
current: usize,
}
impl Odd {
pub fn new() -> Odd {
Odd { current: 1 }
}
}
impl Iterator for Odd {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> {
self.current += 2;
Some(self.current - 2)
}
}