1
Fork 0

rustdoc: Pre-calculate traits that are in scope for doc links

This eliminates one more late use of resolver
This commit is contained in:
Vadim Petrochenkov 2021-08-29 21:41:46 +03:00
parent 17dfae79bb
commit 00ba815a58
7 changed files with 131 additions and 41 deletions

View file

@ -614,7 +614,8 @@ impl<'a> ModuleData<'a> {
}
}
fn def_id(&self) -> DefId {
// Public for rustdoc.
pub fn def_id(&self) -> DefId {
self.opt_def_id().expect("`ModuleData::def_id` is called on a block module")
}
@ -3407,6 +3408,16 @@ impl<'a> Resolver<'a> {
&self.all_macros
}
/// For rustdoc.
/// For local modules returns only reexports, for external modules returns all children.
pub fn module_children_or_reexports(&self, def_id: DefId) -> Vec<ModChild> {
if let Some(def_id) = def_id.as_local() {
self.reexport_map.get(&def_id).cloned().unwrap_or_default()
} else {
self.cstore().module_children_untracked(def_id, self.session)
}
}
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
#[inline]
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {