Fix ICE on pub macro
s defined within a non-module type namespace.
This commit is contained in:
parent
ce3ecd612f
commit
255f107cac
@ -93,6 +93,7 @@ fn store_path(&mut self, did: DefId) {
|
||||
});
|
||||
// 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 {
|
||||
let path_segment_ty_ns = match path_segment.data {
|
||||
@ -106,11 +107,18 @@ fn store_path(&mut self, did: DefId) {
|
||||
continue 'exported_macros;
|
||||
}
|
||||
};
|
||||
cur_mod = cur_mod
|
||||
.mods
|
||||
.iter_mut()
|
||||
.find(|module| module.name == Some(path_segment_ty_ns))
|
||||
.unwrap();
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
cur_mod.macros.push((def, None));
|
||||
}
|
||||
|
@ -72,3 +72,11 @@ pub mod both_fn_and_mod {
|
||||
pub mod __ {
|
||||
// @!has krate/__/macro.in_both_const_and_mod.html
|
||||
}
|
||||
|
||||
enum Enum {
|
||||
Crazy = {
|
||||
// @!has krate/macro.this_is_getting_weird.html;
|
||||
pub macro this_is_getting_weird() {}
|
||||
42
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user