Skip to content

Commit 4c8e38a

Browse files
authored
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`
2 parents f6677b0 + 681ccca commit 4c8e38a

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/librustdoc/clean/mod.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -2161,18 +2161,20 @@ fn clean_use_statement(
21612161
return Vec::new();
21622162
}
21632163

2164-
let (doc_meta_item, please_inline) = import.attrs.lists(sym::doc).get_word_attr(sym::inline);
2164+
let inline_attr = import.attrs.lists(sym::doc).get_word_attr(sym::inline);
21652165
let pub_underscore = import.vis.node.is_pub() && name == kw::Underscore;
21662166

2167-
if pub_underscore && please_inline {
2168-
rustc_errors::struct_span_err!(
2169-
cx.tcx.sess,
2170-
doc_meta_item.unwrap().span(),
2171-
E0780,
2172-
"anonymous imports cannot be inlined"
2173-
)
2174-
.span_label(import.span, "anonymous import")
2175-
.emit();
2167+
if pub_underscore {
2168+
if let Some(ref inline) = inline_attr {
2169+
rustc_errors::struct_span_err!(
2170+
cx.tcx.sess,
2171+
inline.span(),
2172+
E0780,
2173+
"anonymous imports cannot be inlined"
2174+
)
2175+
.span_label(import.span, "anonymous import")
2176+
.emit();
2177+
}
21762178
}
21772179

21782180
// We consider inlining the documentation of `pub use` statements, but we
@@ -2205,7 +2207,7 @@ fn clean_use_statement(
22052207
}
22062208
Import::new_glob(resolve_use_source(cx, path), true)
22072209
} else {
2208-
if !please_inline {
2210+
if inline_attr.is_none() {
22092211
if let Res::Def(DefKind::Mod, did) = path.res {
22102212
if !did.is_local() && did.index == CRATE_DEF_INDEX {
22112213
// if we're `pub use`ing an extern crate root, don't inline it unless we

src/librustdoc/clean/types.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ impl AttributesExt for [ast::Attribute] {
438438
crate trait NestedAttributesExt {
439439
/// Returns `true` if the attribute list contains a specific `Word`
440440
fn has_word(self, word: Symbol) -> bool;
441-
fn get_word_attr(self, word: Symbol) -> (Option<ast::NestedMetaItem>, bool);
441+
fn get_word_attr(self, word: Symbol) -> Option<ast::NestedMetaItem>;
442442
}
443443

444444
impl<I: Iterator<Item = ast::NestedMetaItem> + IntoIterator<Item = ast::NestedMetaItem>>
@@ -448,11 +448,8 @@ impl<I: Iterator<Item = ast::NestedMetaItem> + IntoIterator<Item = ast::NestedMe
448448
self.into_iter().any(|attr| attr.is_word() && attr.has_name(word))
449449
}
450450

451-
fn get_word_attr(mut self, word: Symbol) -> (Option<ast::NestedMetaItem>, bool) {
452-
match self.find(|attr| attr.is_word() && attr.has_name(word)) {
453-
Some(a) => (Some(a), true),
454-
None => (None, false),
455-
}
451+
fn get_word_attr(mut self, word: Symbol) -> Option<ast::NestedMetaItem> {
452+
self.find(|attr| attr.is_word() && attr.has_name(word))
456453
}
457454
}
458455

0 commit comments

Comments
 (0)