@@ -75,7 +75,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
75
75
// moving them back to their correct locations.
76
76
' exported_macros: for def in krate. exported_macros {
77
77
// The `def` of a macro in `exported_macros` should correspond to either:
78
- // - a `#[macro-export ] macro_rules!` macro,
78
+ // - a `#[macro_export ] macro_rules!` macro,
79
79
// - a built-in `derive` (or attribute) macro such as the ones in `::core`,
80
80
// - a `pub macro`.
81
81
// Only the last two need to be fixed, thus:
@@ -84,17 +84,18 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
84
84
continue ' exported_macros;
85
85
}
86
86
let tcx = self . cx . tcx ;
87
- /* Because of #77828 we cannot do the simpler:
88
- let macro_parent_module = tcx.def_path(tcx.parent_module(def.hir_id).to_def_id());
89
- // and instead have to do: */
90
- let macro_parent_module = tcx . def_path ( {
87
+ // Note: this is not the same as `.parent_module()`. Indeed, the latter looks
88
+ // for the closest module _ancestor_, which is not necessarily a direct parent
89
+ // (since a direct parent isn't necessarily a module, c.f. #77828).
90
+ let macro_parent_def_id = {
91
91
use rustc_middle:: ty:: DefIdTree ;
92
92
tcx. parent ( tcx. hir ( ) . local_def_id ( def. hir_id ) . to_def_id ( ) ) . unwrap ( )
93
- } ) ;
93
+ } ;
94
+ let macro_parent_path = tcx. def_path ( macro_parent_def_id) ;
94
95
// HACK: rustdoc has no way to lookup `doctree::Module`s by their HirId. Instead,
95
96
// lookup the module by its name, by looking at each path segment one at a time.
96
97
let mut cur_mod = & mut top_level_module;
97
- for path_segment in macro_parent_module . data {
98
+ for path_segment in macro_parent_path . data {
98
99
// Path segments may refer to a module (in which case they belong to the type
99
100
// namespace), which is _necessary_ for the macro to be accessible outside it
100
101
// (no "associated macros" as of yet). Else we bail with an outer `continue`.
@@ -108,6 +109,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
108
109
None => continue ' exported_macros,
109
110
}
110
111
}
112
+ let cur_mod_def_id = tcx. hir ( ) . local_def_id ( cur_mod. id ) . to_def_id ( ) ;
113
+ assert_eq ! ( cur_mod_def_id, macro_parent_def_id) ;
111
114
cur_mod. macros . push ( ( def, None ) ) ;
112
115
}
113
116
self . cx . renderinfo . get_mut ( ) . exact_paths = self . exact_paths ;
0 commit comments