diff options
| author | bors <bors@rust-lang.org> | 2022-01-26 09:10:27 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-01-26 09:10:27 +0000 | 
| commit | 788b1fe5b79a8b74215022f9df49b0eae68a50b9 (patch) | |
| tree | 76d78463e73fcf56e3674b834e330191979656c9 /compiler/rustc_resolve | |
| parent | d502eda250d0090f4990cc6880c88b95a92b4818 (diff) | |
| parent | 00ba815a585d11957b3764fda61ac0b120844b02 (diff) | |
| download | rust-788b1fe5b79a8b74215022f9df49b0eae68a50b9.tar.gz rust-788b1fe5b79a8b74215022f9df49b0eae68a50b9.zip | |
Auto merge of #88679 - petrochenkov:doctrscope, r=GuillaumeGomez
rustdoc: Pre-calculate traits that are in scope for doc links This eliminates one more late use of resolver (part of #83761). At early doc link resolution time we go through parent modules of items from the current crate, reexports of items from other crates, trait items, and impl items collected by `collect-intra-doc-links` pass, determine traits that are in scope in each such module, and put those traits into a map used by later rustdoc passes. r? `@jyn514`
Diffstat (limited to 'compiler/rustc_resolve')
| -rw-r--r-- | compiler/rustc_resolve/src/build_reduced_graph.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 13 | 
2 files changed, 13 insertions, 2 deletions
| diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 631b8fef668..e4d8b7d5283 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -108,7 +108,7 @@ impl<'a> Resolver<'a> { /// Reachable macros with block module parents exist due to `#[macro_export] macro_rules!`, /// but they cannot use def-site hygiene, so the assumption holds /// (<https://github.com/rust-lang/rust/pull/77984#issuecomment-712445508>). - crate fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Module<'a> { + pub fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Module<'a> { loop { match self.get_module(def_id) { Some(module) => return module, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index f6625ac021b..45cc64ea194 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -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> { | 
