Fix rebase and clean up some code.
This commit is contained in:
parent
a4de27aeec
commit
0311fe98e0
@ -93,38 +93,24 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
});
|
||||
// HACK: rustdoc has no way to lookup `doctree::Module`s by their HirId. Instead,
|
||||
// lookup the module by its name, by looking at each path segment one at a time.
|
||||
// Once #80415 is merged, this whole `for` loop research can be replaced by that.
|
||||
let mut cur_mod = &mut top_level_module;
|
||||
for path_segment in macro_parent_module.data {
|
||||
// Path segments may refer to a module (in which case they belong to the type
|
||||
// namespace), which is _necessary_ for the macro to be accessible outside it
|
||||
// (no "associated macros" as of yet). Else we bail with an outer `continue`.
|
||||
let path_segment_ty_ns = match path_segment.data {
|
||||
rustc_hir::definitions::DefPathData::TypeNs(symbol) => symbol,
|
||||
_ => {
|
||||
// If the path segment is not from the type namespace
|
||||
// (_e.g._, it can be from a value namespace in the case of `f::` in:
|
||||
// `fn f() { pub macro m() {} }`
|
||||
// then the item is not accessible, and should thus act as if it didn't
|
||||
// exist (unless "associated macros" (inside an `impl`) were a thing…).
|
||||
continue 'exported_macros;
|
||||
}
|
||||
_ => continue 'exported_macros,
|
||||
};
|
||||
// The obtained name in the type namespace may belong to something that is not
|
||||
// a `mod`ule (_e.g._, it could be an `enum` with a `pub macro` defined within
|
||||
// the block used for a discriminant.
|
||||
if let Some(child_mod) =
|
||||
cur_mod.mods.iter_mut().find(|module| module.name == Some(path_segment_ty_ns))
|
||||
{
|
||||
cur_mod = child_mod;
|
||||
} else {
|
||||
// If the macro's parent def path is not exclusively made of module
|
||||
// components, then it is not accessible (c.f. previous `continue`).
|
||||
continue 'exported_macros;
|
||||
// Descend into the child module that matches this path segment (if any).
|
||||
match cur_mod.mods.iter_mut().find(|child| child.name == Some(path_segment_ty_ns)) {
|
||||
Some(child_mod) => cur_mod = &mut *child_mod,
|
||||
None => continue 'exported_macros,
|
||||
}
|
||||
}
|
||||
cur_mod.macros.push((def, None));
|
||||
}
|
||||
|
||||
self.cx.renderinfo.get_mut().exact_paths = self.exact_paths;
|
||||
|
||||
top_level_module
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user