Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Clean up NestedAttributesExt trait/implementation #92188

Merged
merged 1 commit into from
Jan 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down