]> git.lizzy.rs Git - rust.git/commitdiff
* Fix some typo
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Sun, 14 Feb 2021 13:47:55 +0000 (14:47 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 23 Feb 2021 20:58:17 +0000 (21:58 +0100)
* Improve documentation
* Add a test to ensure that spotlighted traits from dependencies are taken into account as expected

src/librustdoc/clean/utils.rs
src/librustdoc/formats/cache.rs
src/test/rustdoc/spotlight-from-dependency.rs [new file with mode: 0644]

index 92f9f5991e28ebf7360aad7f875a8d23a4a13056..0089a3838f423d3e2ab41bee9692d95ee713a6fe 100644 (file)
@@ -521,14 +521,15 @@ fn print_const_with_custom_print_scalar(cx: &DocContext<'_>, ct: &'tcx ty::Const
     }
 }
 
     }
 }
 
-/// 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)
 crate fn has_doc_flag(attrs: Attributes<'_>, flag: Symbol) -> bool {
     attrs.iter().any(|attr| {
         attr.has_name(sym::doc)
index ef4e0e0d57c920565b87d954f008689866f2b644..e9c5dd50d59a82df5cd47de3f5b5bfd759b8fd35 100644 (file)
@@ -245,16 +245,12 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
             }
         }
 
             }
         }
 
-        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(),
         // 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 (file)
index 0000000..ed42c43
--- /dev/null
@@ -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)
+    }
+}