Rename to inline_attr and use if-let to extract NestedMetaItem

This commit is contained in:
Yusuke Tanaka 2021-02-13 01:48:00 +09:00
parent 715c19e75e
commit 681cccad57
No known key found for this signature in database
GPG Key ID: 409D7EEE1E7A716A

View File

@ -2163,19 +2163,20 @@ fn clean_use_statement(
return Vec::new();
}
let doc_meta_item = import.attrs.lists(sym::doc).get_word_attr(sym::inline);
let please_inline = doc_meta_item.is_some();
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
@ -2208,7 +2209,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