]> git.lizzy.rs Git - rust.git/commitdiff
Clean up NestedAttributesExt trait/implementation
authorRoc Yu <rocyu@protonmail.com>
Wed, 22 Dec 2021 20:37:49 +0000 (15:37 -0500)
committerRoc Yu <rocyu@protonmail.com>
Thu, 23 Dec 2021 22:58:59 +0000 (17:58 -0500)
src/librustdoc/clean/types.rs

index cb4896fbfd23ddfed38c3d9bbc026b2dd8286b5b..fc26b82c974f81ac7494bb2ad1e52275bc416800 100644 (file)
@@ -879,20 +879,25 @@ fn single<T: IntoIterator>(it: T) -> Option<T::Item> {
 }
 
 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))
     }
 }