Refactor get_word_attr to return only Option

This commit is contained in:
Yusuke Tanaka 2021-02-13 01:13:50 +09:00
parent a118ee2c13
commit 715c19e75e
No known key found for this signature in database
GPG key ID: 409D7EEE1E7A716A
2 changed files with 5 additions and 7 deletions

View file

@ -2163,7 +2163,8 @@ fn clean_use_statement(
return Vec::new();
}
let (doc_meta_item, please_inline) = import.attrs.lists(sym::doc).get_word_attr(sym::inline);
let doc_meta_item = import.attrs.lists(sym::doc).get_word_attr(sym::inline);
let please_inline = doc_meta_item.is_some();
let pub_underscore = import.vis.node.is_pub() && name == kw::Underscore;
if pub_underscore && please_inline {

View file

@ -438,7 +438,7 @@ 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;
fn get_word_attr(self, word: Symbol) -> (Option<ast::NestedMetaItem>, bool);
fn get_word_attr(self, word: Symbol) -> Option<ast::NestedMetaItem>;
}
impl<I: Iterator<Item = ast::NestedMetaItem> + IntoIterator<Item = ast::NestedMetaItem>>
@ -448,11 +448,8 @@ impl<I: Iterator<Item = ast::NestedMetaItem> + IntoIterator<Item = ast::NestedMe
self.into_iter().any(|attr| attr.is_word() && attr.has_name(word))
}
fn get_word_attr(mut self, word: Symbol) -> (Option<ast::NestedMetaItem>, bool) {
match self.find(|attr| attr.is_word() && attr.has_name(word)) {
Some(a) => (Some(a), true),
None => (None, false),
}
fn get_word_attr(mut self, word: Symbol) -> Option<ast::NestedMetaItem> {
self.find(|attr| attr.is_word() && attr.has_name(word))
}
}