Skip to content

Commit

Permalink
Rollup merge of #82033 - magurotuna:issue82016, r=jyn514
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
JohnTitor authored Feb 13, 2021
2 parents f6677b0 + 681ccca commit 4c8e38a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
24 changes: 13 additions & 11 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>
Expand All @@ -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))
}
}

Expand Down

0 comments on commit 4c8e38a

Please sign in to comment.