* 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:
parent
b5c8eea55d
commit
3c59e64abf
@ -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
|
||||
/// `clean::Attributes`.
|
||||
/// This function exists because it runs on `hir::Attributes` whereas the other is a
|
||||
/// `clean::Attributes` method.
|
||||
crate fn has_doc_flag(attrs: Attributes<'_>, flag: Symbol) -> bool {
|
||||
attrs.iter().any(|attr| {
|
||||
attr.has_name(sym::doc)
|
||||
|
@ -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
|
||||
// trait.
|
||||
if let clean::TraitItem(ref t) = *item.kind {
|
||||
self.cache.traits.entry(item.def_id).or_insert_with(|| clean::TraitWithExtraInfo {
|
||||
trait_: t.clone(),
|
||||
is_spotlight: clean::utils::has_doc_flag(
|
||||
tcx.get_attrs(item.def_id),
|
||||
sym::spotlight,
|
||||
),
|
||||
is_spotlight: item.attrs.has_doc_flag(sym::spotlight),
|
||||
});
|
||||
}
|
||||
|
||||
|
24
src/test/rustdoc/spotlight-from-dependency.rs
Normal file
24
src/test/rustdoc/spotlight-from-dependency.rs
Normal 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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user