diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-02-13 16:36:48 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-13 16:36:48 +0900 |
| commit | 4c8e38aa60c4dc36b44725bc956cd19ff6e9f6ac (patch) | |
| tree | 0910deef139f20d95ebafd06c438b64c911e8316 | |
| parent | f6677b0f52e2e4bb557945652f03cd1b4bf55c4a (diff) | |
| parent | 681cccad571c99673be4e2ad14bc2048e8894ac8 (diff) | |
| download | rust-4c8e38aa60c4dc36b44725bc956cd19ff6e9f6ac.tar.gz rust-4c8e38aa60c4dc36b44725bc956cd19ff6e9f6ac.zip | |
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`
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 24 | ||||
| -rw-r--r-- | src/librustdoc/clean/types.rs | 9 |
2 files changed, 16 insertions, 17 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a0ab6ed4a4c..7e7e417bb65 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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 diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 9b8e04a1d23..e1ccbfd9da9 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -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)) } } |
