Skip to content

Commit 3c59e64

Browse files
* Fix some typo
* Improve documentation * Add a test to ensure that spotlighted traits from dependencies are taken into account as expected
1 parent b5c8eea commit 3c59e64

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/librustdoc/clean/utils.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,15 @@ crate fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<De
521521
}
522522
}
523523

524-
/// Checks that one attribute is `doc`. For example:
524+
/// Checks for the existence of `hidden` in the attribute below if `flag` is `sym::hidden`:
525525
///
526-
/// ```text
527-
/// #[doc(spotlight)]
526+
/// ```
527+
/// #[doc(hidden)]
528+
/// pub fn foo() {}
528529
/// ```
529530
///
530-
/// This function has to exists because it runs on `hir::Attributes` whereas the other runs on
531-
/// `clean::Attributes`.
531+
/// This function exists because it runs on `hir::Attributes` whereas the other is a
532+
/// `clean::Attributes` method.
532533
crate fn has_doc_flag(attrs: Attributes<'_>, flag: Symbol) -> bool {
533534
attrs.iter().any(|attr| {
534535
attr.has_name(sym::doc)

src/librustdoc/formats/cache.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,12 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
245245
}
246246
}
247247

248-
let tcx = self.tcx;
249248
// Propagate a trait method's documentation to all implementors of the
250249
// trait.
251250
if let clean::TraitItem(ref t) = *item.kind {
252251
self.cache.traits.entry(item.def_id).or_insert_with(|| clean::TraitWithExtraInfo {
253252
trait_: t.clone(),
254-
is_spotlight: clean::utils::has_doc_flag(
255-
tcx.get_attrs(item.def_id),
256-
sym::spotlight,
257-
),
253+
is_spotlight: item.attrs.has_doc_flag(sym::spotlight),
258254
});
259255
}
260256

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![crate_name = "foo"]
2+
3+
use std::iter::Iterator;
4+
5+
// @has foo/struct.Odd.html
6+
// @has - '//h4[@id="method.new"]//span[@class="notable-traits"]//code/span' 'impl Iterator for Odd'
7+
pub struct Odd {
8+
current: usize,
9+
}
10+
11+
impl Odd {
12+
pub fn new() -> Odd {
13+
Odd { current: 1 }
14+
}
15+
}
16+
17+
impl Iterator for Odd {
18+
type Item = usize;
19+
20+
fn next(&mut self) -> Option<Self::Item> {
21+
self.current += 2;
22+
Some(self.current - 2)
23+
}
24+
}

0 commit comments

Comments
 (0)