@@ -93,38 +93,24 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
93
93
} ) ;
94
94
// HACK: rustdoc has no way to lookup `doctree::Module`s by their HirId. Instead,
95
95
// 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.
97
96
let mut cur_mod = & mut top_level_module;
98
97
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`.
99
101
let path_segment_ty_ns = match path_segment. data {
100
102
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,
109
104
} ;
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,
121
109
}
122
110
}
123
111
cur_mod. macros . push ( ( def, None ) ) ;
124
112
}
125
-
126
113
self . cx . renderinfo . get_mut ( ) . exact_paths = self . exact_paths ;
127
-
128
114
top_level_module
129
115
}
130
116
0 commit comments