rustdoc: Keep full ParentScope
during early doc link resolution
This commit is contained in:
parent
921f63fb1f
commit
044e45c595
3 changed files with 36 additions and 30 deletions
|
@ -143,7 +143,7 @@ enum ScopeSet<'a> {
|
|||
/// but not for late resolution yet.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct ParentScope<'a> {
|
||||
module: Module<'a>,
|
||||
pub module: Module<'a>,
|
||||
expansion: LocalExpnId,
|
||||
macro_rules: MacroRulesScopeRef<'a>,
|
||||
derives: &'a [ast::Path],
|
||||
|
@ -1874,25 +1874,25 @@ impl<'a> Resolver<'a> {
|
|||
&mut self,
|
||||
path_str: &str,
|
||||
ns: Namespace,
|
||||
mut module_id: DefId,
|
||||
mut parent_scope: ParentScope<'a>,
|
||||
) -> Option<Res> {
|
||||
let mut segments =
|
||||
Vec::from_iter(path_str.split("::").map(Ident::from_str).map(Segment::from_ident));
|
||||
if let Some(segment) = segments.first_mut() {
|
||||
if segment.ident.name == kw::Crate {
|
||||
// FIXME: `resolve_path` always resolves `crate` to the current crate root, but
|
||||
// rustdoc wants it to resolve to the `module_id`'s crate root. This trick of
|
||||
// rustdoc wants it to resolve to the `parent_scope`'s crate root. This trick of
|
||||
// replacing `crate` with `self` and changing the current module should achieve
|
||||
// the same effect.
|
||||
segment.ident.name = kw::SelfLower;
|
||||
module_id = module_id.krate.as_def_id();
|
||||
parent_scope.module =
|
||||
self.expect_module(parent_scope.module.def_id().krate.as_def_id());
|
||||
} else if segment.ident.name == kw::Empty {
|
||||
segment.ident.name = kw::PathRoot;
|
||||
}
|
||||
}
|
||||
|
||||
let module = self.expect_module(module_id);
|
||||
match self.maybe_resolve_path(&segments, Some(ns), &ParentScope::module(module, self)) {
|
||||
match self.maybe_resolve_path(&segments, Some(ns), &parent_scope) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => Some(module.res().unwrap()),
|
||||
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
|
||||
Some(path_res.base_res())
|
||||
|
@ -1904,11 +1904,6 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
// For rustdoc.
|
||||
pub fn graph_root(&self) -> Module<'a> {
|
||||
self.graph_root
|
||||
}
|
||||
|
||||
// For rustdoc.
|
||||
pub fn take_all_macro_rules(&mut self) -> FxHashMap<Symbol, Res> {
|
||||
mem::take(&mut self.all_macro_rules)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue