@@ -73,56 +73,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
7373
7474 crate fn visit ( mut self , krate : & ' tcx hir:: Crate < ' _ > ) -> Module < ' tcx > {
7575 let span = krate. module ( ) . inner ;
76- let mut top_level_module = self . visit_mod_contents (
76+ let top_level_module = self . visit_mod_contents (
7777 & Spanned { span, node : hir:: VisibilityKind :: Public } ,
7878 hir:: CRATE_HIR_ID ,
7979 & krate. module ( ) ,
8080 self . cx . tcx . crate_name ( LOCAL_CRATE ) ,
8181 ) ;
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+
12683 self . cx . cache . exact_paths = self . exact_paths ;
12784 top_level_module
12885 }
@@ -238,10 +195,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
238195 self . inlining = prev;
239196 true
240197 }
241- Node :: MacroDef ( def) if !glob => {
242- om. macros . push ( ( def, renamed) ) ;
243- true
244- }
245198 _ => false ,
246199 } ;
247200 self . view_item_stack . remove ( & res_hir_id) ;
@@ -257,7 +210,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
257210 debug ! ( "visiting item {:?}" , item) ;
258211 let name = renamed. unwrap_or ( item. ident . name ) ;
259212
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 {
261220 self . store_path ( item. def_id . to_def_id ( ) ) ;
262221 }
263222
@@ -269,7 +228,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
269228 }
270229 }
271230 // If we're inlining, skip private items.
272- _ if self . inlining && !item . vis . node . is_pub ( ) => { }
231+ _ if self . inlining && !is_pub => { }
273232 hir:: ItemKind :: GlobalAsm ( ..) => { }
274233 hir:: ItemKind :: Use ( _, hir:: UseKind :: ListStem ) => { }
275234 hir:: ItemKind :: Use ( ref path, kind) => {
@@ -285,7 +244,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
285244
286245 // If there was a private module in the current path then don't bother inlining
287246 // 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 {
289248 let please_inline = attrs. iter ( ) . any ( |item| match item. meta_item_list ( ) {
290249 Some ( ref list) if item. has_name ( sym:: doc) => {
291250 list. iter ( ) . any ( |i| i. has_name ( sym:: inline) )
@@ -311,6 +270,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
311270 om. mods . push ( self . visit_mod_contents ( & item. vis , item. hir_id ( ) , m, name) ) ;
312271 }
313272 hir:: ItemKind :: Fn ( ..)
273+ | hir:: ItemKind :: Macro { .. }
314274 | hir:: ItemKind :: ExternCrate ( ..)
315275 | hir:: ItemKind :: Enum ( ..)
316276 | hir:: ItemKind :: Struct ( ..)
0 commit comments