about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-02-14 14:47:55 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2021-02-23 21:58:17 +0100
commit3c59e64abf99f57baca9493e1ffe66844074e677 (patch)
treed0499f0be2ce87aff3adbd220a89176d973ad638
parentb5c8eea55d160f524305d09ad45c0d79493537b4 (diff)
downloadrust-3c59e64abf99f57baca9493e1ffe66844074e677.tar.gz
rust-3c59e64abf99f57baca9493e1ffe66844074e677.zip
* Fix some typo
* Improve documentation
* Add a test to ensure that spotlighted traits from dependencies are taken into account as expected
-rw-r--r--src/librustdoc/clean/utils.rs11
-rw-r--r--src/librustdoc/formats/cache.rs6
-rw-r--r--src/test/rustdoc/spotlight-from-dependency.rs24
3 files changed, 31 insertions, 10 deletions
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index 92f9f5991e2..0089a3838f4 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -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)
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs
index ef4e0e0d57c..e9c5dd50d59 100644
--- a/src/librustdoc/formats/cache.rs
+++ b/src/librustdoc/formats/cache.rs
@@ -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),
             });
         }
 
diff --git a/src/test/rustdoc/spotlight-from-dependency.rs b/src/test/rustdoc/spotlight-from-dependency.rs
new file mode 100644
index 00000000000..ed42c435945
--- /dev/null
+++ b/src/test/rustdoc/spotlight-from-dependency.rs
@@ -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)
+    }
+}