@@ -93,38 +93,24 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
9393 } ) ;
9494 // HACK: rustdoc has no way to lookup `doctree::Module`s by their HirId. Instead,
9595 // lookup the module by its name, by looking at each path segment one at a time.
96- // Once #80415 is merged, this whole `for` loop research can be replaced by that.
9796 let mut cur_mod = & mut top_level_module;
9897 for path_segment in macro_parent_module. data {
98+ // Path segments may refer to a module (in which case they belong to the type
99+ // namespace), which is _necessary_ for the macro to be accessible outside it
100+ // (no "associated macros" as of yet). Else we bail with an outer `continue`.
99101 let path_segment_ty_ns = match path_segment. data {
100102 rustc_hir:: definitions:: DefPathData :: TypeNs ( symbol) => symbol,
101- _ => {
102- // If the path segment is not from the type namespace
103- // (_e.g._, it can be from a value namespace in the case of `f::` in:
104- // `fn f() { pub macro m() {} }`
105- // then the item is not accessible, and should thus act as if it didn't
106- // exist (unless "associated macros" (inside an `impl`) were a thing…).
107- continue ' exported_macros;
108- }
103+ _ => continue ' exported_macros,
109104 } ;
110- // The obtained name in the type namespace may belong to something that is not
111- // a `mod`ule (_e.g._, it could be an `enum` with a `pub macro` defined within
112- // the block used for a discriminant.
113- if let Some ( child_mod) =
114- cur_mod. mods . iter_mut ( ) . find ( |module| module. name == Some ( path_segment_ty_ns) )
115- {
116- cur_mod = child_mod;
117- } else {
118- // If the macro's parent def path is not exclusively made of module
119- // components, then it is not accessible (c.f. previous `continue`).
120- continue ' exported_macros;
105+ // Descend into the child module that matches this path segment (if any).
106+ match cur_mod. mods . iter_mut ( ) . find ( |child| child. name == Some ( path_segment_ty_ns) ) {
107+ Some ( child_mod) => cur_mod = & mut * child_mod,
108+ None => continue ' exported_macros,
121109 }
122110 }
123111 cur_mod. macros . push ( ( def, None ) ) ;
124112 }
125-
126113 self . cx . renderinfo . get_mut ( ) . exact_paths = self . exact_paths ;
127-
128114 top_level_module
129115 }
130116
0 commit comments