diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2023-06-07 18:01:29 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-07 18:01:29 +0530 |
| commit | c6fda401f6d03c3947c6604a709e6a6239c76c4f (patch) | |
| tree | 41b8f01ae970bcf1b64ca24288d9e6e54775cd48 | |
| parent | 0b002eb90692cd30f09b3ed37b2fab55dfc6427a (diff) | |
| parent | 0f1aaef7e9a1776a81819ef4ae05b508fb12d572 (diff) | |
| download | rust-c6fda401f6d03c3947c6604a709e6a6239c76c4f.tar.gz rust-c6fda401f6d03c3947c6604a709e6a6239c76c4f.zip | |
Rollup merge of #112251 - notriddle:notriddle/cleanup-inlining, r=GuillaumeGomez
rustdoc: convert `if let Some()` that always matches to variable
| -rw-r--r-- | src/librustdoc/visit_ast.rs | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index db353552893..22c8cc09243 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -14,7 +14,7 @@ use rustc_span::hygiene::MacroKind; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; -use std::{iter, mem}; +use std::mem; use crate::clean::{cfg::Cfg, reexport_chain, AttributesExt, NestedAttributesExt}; use crate::core; @@ -291,27 +291,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { if !please_inline { let inherits_hidden = inherits_doc_hidden(tcx, res_did, None); // Only inline if requested or if the item would otherwise be stripped. - // - // If it's a doc hidden module, we need to keep it in case some of its inner items - // are re-exported. if (!is_private && !inherits_hidden) || ( is_hidden && + // If it's a doc hidden module, we need to keep it in case some of its inner items + // are re-exported. !matches!(item, Node::Item(&hir::Item { kind: hir::ItemKind::Mod(_), .. })) - ) { - return false; - } else if let Some(item_def_id) = reexport_chain(tcx, def_id, res_did).iter() - .flat_map(|reexport| reexport.id()).map(|id| id.expect_local()) - .chain(iter::once(res_did)).nth(1) && - item_def_id != def_id && - self - .cx - .cache - .effective_visibilities - .is_directly_public(tcx, item_def_id.to_def_id()) && - !tcx.is_doc_hidden(item_def_id) && - !inherits_doc_hidden(tcx, item_def_id, None) - { + ) || // The imported item is public and not `doc(hidden)` so no need to inline it. + self.reexport_public_and_not_hidden(def_id, res_did) + { return false; } } @@ -359,6 +347,28 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { ret } + /// Returns `true` if the item is visible, meaning it's not `#[doc(hidden)]` or private. + /// + /// This function takes into account the entire re-export `use` chain, so it needs the + /// ID of the "leaf" `use` and the ID of the "root" item. + fn reexport_public_and_not_hidden( + &self, + import_def_id: LocalDefId, + target_def_id: LocalDefId, + ) -> bool { + let tcx = self.cx.tcx; + let item_def_id = reexport_chain(tcx, import_def_id, target_def_id) + .iter() + .flat_map(|reexport| reexport.id()) + .map(|id| id.expect_local()) + .nth(1) + .unwrap_or(target_def_id); + item_def_id != import_def_id + && self.cx.cache.effective_visibilities.is_directly_public(tcx, item_def_id.to_def_id()) + && !tcx.is_doc_hidden(item_def_id) + && !inherits_doc_hidden(tcx, item_def_id, None) + } + #[inline] fn add_to_current_mod( &mut self, |
