diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2023-07-25 15:39:45 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2023-07-25 15:39:45 +0200 |
| commit | 1f828f01552b54abb8e33610484d9269067fcc28 (patch) | |
| tree | d4e81a8de80921470239731089e721adc508ce40 | |
| parent | 988729d842be9fddeecdf8bd9c8cf018b511ed8b (diff) | |
| download | rust-1f828f01552b54abb8e33610484d9269067fcc28.tar.gz rust-1f828f01552b54abb8e33610484d9269067fcc28.zip | |
Improve performance of `first_non_private`
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2ffe38c2403..743ba6835db 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1545,7 +1545,7 @@ fn first_non_private<'tcx>( if let Some((segments, span)) = saved_path { return Some(first_non_private_clean_path(cx, path, segments, span)); } - let (parent_def_id, mut ident) = match &path.segments[..] { + let (parent_def_id, ident) = match &path.segments[..] { [] => return None, // Relative paths are available in the same scope as the owner. [leaf] => (cx.tcx.local_parent(hir_id.owner.def_id), leaf.ident), @@ -1569,6 +1569,7 @@ fn first_non_private<'tcx>( // Absolute paths are not. We start from the parent of the item. [.., parent, leaf] => (parent.res.opt_def_id()?.as_local()?, leaf.ident), }; + let hir = cx.tcx.hir(); // First we try to get the `DefId` of the item. for child in cx.tcx.module_children_local(parent_def_id).iter().filter(move |c| c.ident == ident) @@ -1581,29 +1582,24 @@ fn first_non_private<'tcx>( let mut last_path_res = None; 'reexps: for reexp in child.reexport_chain.iter() { if let Some(use_def_id) = reexp.id() && - let Some(local_use_def_id) = use_def_id.as_local() + let Some(local_use_def_id) = use_def_id.as_local() && + let Some(hir::Node::Item(item)) = hir.find_by_def_id(local_use_def_id) && + let hir::ItemKind::Use(path, _) = item.kind { - let hir = cx.tcx.hir(); - for item_id in hir.module_items(cx.tcx.local_parent(local_use_def_id)) { - let item = hir.item(item_id); - if item.ident == ident && let hir::ItemKind::Use(path, _) = item.kind { - for res in &path.res { - if let Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) = res { - continue; - } - if (cx.render_options.document_hidden || - !cx.tcx.is_doc_hidden(use_def_id)) && - // We never check for "cx.render_options.document_private" - // because if a re-export is not fully public, it's never - // documented. - cx.tcx.local_visibility(local_use_def_id).is_public() { - break 'reexps; - } - ident = path.segments.last().unwrap().ident; - last_path_res = Some((path, res)); - continue 'reexps; - } + for res in &path.res { + if let Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) = res { + continue; + } + if (cx.render_options.document_hidden || + !cx.tcx.is_doc_hidden(use_def_id)) && + // We never check for "cx.render_options.document_private" + // because if a re-export is not fully public, it's never + // documented. + cx.tcx.local_visibility(local_use_def_id).is_public() { + break 'reexps; } + last_path_res = Some((path, res)); + continue 'reexps; } } } |
