about summary refs log tree commit diff
path: root/src/librustdoc
diff options
context:
space:
mode:
authorRoc Yu <rocyu@protonmail.com>2021-12-22 15:37:49 -0500
committerRoc Yu <rocyu@protonmail.com>2021-12-23 17:58:59 -0500
commit91fe2d0ed7a8f79a64216c7328b2bea11a3bc9ea (patch)
tree28f7d2458b5ffe3503c92034a2c0492381db357f /src/librustdoc
parentc09a9529c51cde41c1101e56049d418edb07bf71 (diff)
downloadrust-91fe2d0ed7a8f79a64216c7328b2bea11a3bc9ea.tar.gz
rust-91fe2d0ed7a8f79a64216c7328b2bea11a3bc9ea.zip
Clean up NestedAttributesExt trait/implementation
Diffstat (limited to 'src/librustdoc')
-rw-r--r--src/librustdoc/clean/types.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index cb4896fbfd2..fc26b82c974 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -879,20 +879,25 @@ impl AttributesExt for [ast::Attribute] {
 }
 
 crate trait NestedAttributesExt {
-    /// Returns `true` if the attribute list contains a specific `Word`
-    fn has_word(self, word: Symbol) -> bool;
+    /// Returns `true` if the attribute list contains a specific `word`
+    fn has_word(self, word: Symbol) -> bool
+    where
+        Self: std::marker::Sized,
+    {
+        <Self as NestedAttributesExt>::get_word_attr(self, word).is_some()
+    }
+
+    /// Returns `Some(attr)` if the attribute list contains 'attr'
+    /// corresponding to a specific `word`
     fn get_word_attr(self, word: Symbol) -> Option<ast::NestedMetaItem>;
 }
 
-impl<I: Iterator<Item = ast::NestedMetaItem> + IntoIterator<Item = ast::NestedMetaItem>>
-    NestedAttributesExt for I
+impl<I> NestedAttributesExt for I
+where
+    I: IntoIterator<Item = ast::NestedMetaItem>,
 {
-    fn has_word(self, word: Symbol) -> bool {
-        self.into_iter().any(|attr| attr.is_word() && attr.has_name(word))
-    }
-
-    fn get_word_attr(mut self, word: Symbol) -> Option<ast::NestedMetaItem> {
-        self.find(|attr| attr.is_word() && attr.has_name(word))
+    fn get_word_attr(self, word: Symbol) -> Option<ast::NestedMetaItem> {
+        self.into_iter().find(|attr| attr.is_word() && attr.has_name(word))
     }
 }