Skip to content

Commit

Permalink
Rollup merge of #92188 - vacuus:nested-attributes-ext, r=jyn514
Browse files Browse the repository at this point in the history
rustdoc: Clean up NestedAttributesExt trait/implementation
  • Loading branch information
matthiaskrgr authored Jan 5, 2022
2 parents e35a4bd + 91fe2d0 commit cc01433
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down

0 comments on commit cc01433

Please sign in to comment.