Skip to content

Commit

Permalink
Fix rebase and clean up some code.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhenrymantilla committed Jan 6, 2021
1 parent a4de27a commit 0311fe9
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 0311fe9

Please sign in to comment.