@@ -73,56 +73,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
73
73
74
74
crate fn visit ( mut self , krate : & ' tcx hir:: Crate < ' _ > ) -> Module < ' tcx > {
75
75
let span = krate. module ( ) . inner ;
76
- let mut top_level_module = self . visit_mod_contents (
76
+ let top_level_module = self . visit_mod_contents (
77
77
& Spanned { span, node : hir:: VisibilityKind :: Public } ,
78
78
hir:: CRATE_HIR_ID ,
79
79
& krate. module ( ) ,
80
80
self . cx . tcx . crate_name ( LOCAL_CRATE ) ,
81
81
) ;
82
- // Attach the crate's exported macros to the top-level module.
83
- // In the case of macros 2.0 (`pub macro`), and for built-in `derive`s or attributes as
84
- // well (_e.g._, `Copy`), these are wrongly bundled in there too, so we need to fix that by
85
- // moving them back to their correct locations.
86
- ' exported_macros: for def in krate. exported_macros ( ) {
87
- // The `def` of a macro in `exported_macros` should correspond to either:
88
- // - a `#[macro_export] macro_rules!` macro,
89
- // - a built-in `derive` (or attribute) macro such as the ones in `::core`,
90
- // - a `pub macro`.
91
- // Only the last two need to be fixed, thus:
92
- if def. ast . macro_rules {
93
- top_level_module. macros . push ( ( def, None ) ) ;
94
- continue ' exported_macros;
95
- }
96
- let tcx = self . cx . tcx ;
97
- // Note: this is not the same as `.parent_module()`. Indeed, the latter looks
98
- // for the closest module _ancestor_, which is not necessarily a direct parent
99
- // (since a direct parent isn't necessarily a module, c.f. #77828).
100
- let macro_parent_def_id = {
101
- use rustc_middle:: ty:: DefIdTree ;
102
- tcx. parent ( def. def_id . to_def_id ( ) ) . unwrap ( )
103
- } ;
104
- let macro_parent_path = tcx. def_path ( macro_parent_def_id) ;
105
- // HACK: rustdoc has no way to lookup `doctree::Module`s by their HirId. Instead,
106
- // lookup the module by its name, by looking at each path segment one at a time.
107
- let mut cur_mod = & mut top_level_module;
108
- for path_segment in macro_parent_path. data {
109
- // Path segments may refer to a module (in which case they belong to the type
110
- // namespace), which is _necessary_ for the macro to be accessible outside it
111
- // (no "associated macros" as of yet). Else we bail with an outer `continue`.
112
- let path_segment_ty_ns = match path_segment. data {
113
- rustc_hir:: definitions:: DefPathData :: TypeNs ( symbol) => symbol,
114
- _ => continue ' exported_macros,
115
- } ;
116
- // Descend into the child module that matches this path segment (if any).
117
- match cur_mod. mods . iter_mut ( ) . find ( |child| child. name == path_segment_ty_ns) {
118
- Some ( child_mod) => cur_mod = & mut * child_mod,
119
- None => continue ' exported_macros,
120
- }
121
- }
122
- let cur_mod_def_id = tcx. hir ( ) . local_def_id ( cur_mod. id ) . to_def_id ( ) ;
123
- assert_eq ! ( cur_mod_def_id, macro_parent_def_id) ;
124
- cur_mod. macros . push ( ( def, None ) ) ;
125
- }
82
+
126
83
self . cx . cache . exact_paths = self . exact_paths ;
127
84
top_level_module
128
85
}
@@ -238,10 +195,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
238
195
self . inlining = prev;
239
196
true
240
197
}
241
- Node :: MacroDef ( def) if !glob => {
242
- om. macros . push ( ( def, renamed) ) ;
243
- true
244
- }
245
198
_ => false ,
246
199
} ;
247
200
self . view_item_stack . remove ( & res_hir_id) ;
@@ -257,7 +210,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
257
210
debug ! ( "visiting item {:?}" , item) ;
258
211
let name = renamed. unwrap_or ( item. ident . name ) ;
259
212
260
- if item. vis . node . is_pub ( ) {
213
+ let is_pub = if let hir:: ItemKind :: Macro { is_exported : true , .. } = item. kind {
214
+ true
215
+ } else {
216
+ item. vis . node . is_pub ( )
217
+ } ;
218
+
219
+ if is_pub {
261
220
self . store_path ( item. def_id . to_def_id ( ) ) ;
262
221
}
263
222
@@ -269,7 +228,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
269
228
}
270
229
}
271
230
// If we're inlining, skip private items.
272
- _ if self . inlining && !item . vis . node . is_pub ( ) => { }
231
+ _ if self . inlining && !is_pub => { }
273
232
hir:: ItemKind :: GlobalAsm ( ..) => { }
274
233
hir:: ItemKind :: Use ( _, hir:: UseKind :: ListStem ) => { }
275
234
hir:: ItemKind :: Use ( ref path, kind) => {
@@ -285,7 +244,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
285
244
286
245
// If there was a private module in the current path then don't bother inlining
287
246
// anything as it will probably be stripped anyway.
288
- if item . vis . node . is_pub ( ) && self . inside_public_path {
247
+ if is_pub && self . inside_public_path {
289
248
let please_inline = attrs. iter ( ) . any ( |item| match item. meta_item_list ( ) {
290
249
Some ( ref list) if item. has_name ( sym:: doc) => {
291
250
list. iter ( ) . any ( |i| i. has_name ( sym:: inline) )
@@ -311,6 +270,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
311
270
om. mods . push ( self . visit_mod_contents ( & item. vis , item. hir_id ( ) , m, name) ) ;
312
271
}
313
272
hir:: ItemKind :: Fn ( ..)
273
+ | hir:: ItemKind :: Macro { .. }
314
274
| hir:: ItemKind :: ExternCrate ( ..)
315
275
| hir:: ItemKind :: Enum ( ..)
316
276
| hir:: ItemKind :: Struct ( ..)
0 commit comments