diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-05 11:26:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-05 11:26:04 +0100 |
| commit | cc01433d56064327441ccd05100b310758a8ddbf (patch) | |
| tree | 7794a7cd2da2d1b4d94c3dfe8001caaa2e06b147 | |
| parent | e35a4bd8d0e99ee77ff466c5b53249d74d6c657c (diff) | |
| parent | 91fe2d0ed7a8f79a64216c7328b2bea11a3bc9ea (diff) | |
| download | rust-cc01433d56064327441ccd05100b310758a8ddbf.tar.gz rust-cc01433d56064327441ccd05100b310758a8ddbf.zip | |
Rollup merge of #92188 - vacuus:nested-attributes-ext, r=jyn514
rustdoc: Clean up NestedAttributesExt trait/implementation
| -rw-r--r-- | src/librustdoc/clean/types.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 2ee5de24687..f0f61bb94c8 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -889,20 +889,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)) } } |
