Rollup merge of #82033 - magurotuna:issue82016, r=jyn514
Refactor `get_word_attr` to return only `Option` This commit removes `bool` from the return type of `NestedAttributesExt::get_word_attr` so it will return only `Option<ast::NestedMetaItem>` for less redundancy. Closes #82016 r? `@jyn514`
This commit is contained in:
commit
4c8e38aa60
@ -2161,18 +2161,20 @@ fn clean_use_statement(
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let (doc_meta_item, please_inline) = import.attrs.lists(sym::doc).get_word_attr(sym::inline);
|
||||
let inline_attr = import.attrs.lists(sym::doc).get_word_attr(sym::inline);
|
||||
let pub_underscore = import.vis.node.is_pub() && name == kw::Underscore;
|
||||
|
||||
if pub_underscore && please_inline {
|
||||
rustc_errors::struct_span_err!(
|
||||
cx.tcx.sess,
|
||||
doc_meta_item.unwrap().span(),
|
||||
E0780,
|
||||
"anonymous imports cannot be inlined"
|
||||
)
|
||||
.span_label(import.span, "anonymous import")
|
||||
.emit();
|
||||
if pub_underscore {
|
||||
if let Some(ref inline) = inline_attr {
|
||||
rustc_errors::struct_span_err!(
|
||||
cx.tcx.sess,
|
||||
inline.span(),
|
||||
E0780,
|
||||
"anonymous imports cannot be inlined"
|
||||
)
|
||||
.span_label(import.span, "anonymous import")
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
||||
// We consider inlining the documentation of `pub use` statements, but we
|
||||
@ -2205,7 +2207,7 @@ fn clean_use_statement(
|
||||
}
|
||||
Import::new_glob(resolve_use_source(cx, path), true)
|
||||
} else {
|
||||
if !please_inline {
|
||||
if inline_attr.is_none() {
|
||||
if let Res::Def(DefKind::Mod, did) = path.res {
|
||||
if !did.is_local() && did.index == CRATE_DEF_INDEX {
|
||||
// if we're `pub use`ing an extern crate root, don't inline it unless we
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user