@@ -25,8 +25,8 @@ pub(crate) struct Module<'hir> {
25
25
pub ( crate ) where_inner : Span ,
26
26
pub ( crate ) mods : Vec < Module < ' hir > > ,
27
27
pub ( crate ) id : hir:: HirId ,
28
- // (item, renamed)
29
- pub ( crate ) items : Vec < ( & ' hir hir:: Item < ' hir > , Option < Symbol > ) > ,
28
+ // (item, renamed, import_id )
29
+ pub ( crate ) items : Vec < ( & ' hir hir:: Item < ' hir > , Option < Symbol > , Option < hir :: HirId > ) > ,
30
30
pub ( crate ) foreigns : Vec < ( & ' hir hir:: ForeignItem < ' hir > , Option < Symbol > ) > ,
31
31
}
32
32
@@ -93,6 +93,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
93
93
hir:: CRATE_HIR_ID ,
94
94
self . cx . tcx . hir ( ) . root_module ( ) ,
95
95
self . cx . tcx . crate_name ( LOCAL_CRATE ) ,
96
+ None ,
96
97
) ;
97
98
98
99
// `#[macro_export] macro_rules!` items are reexported at the top level of the
@@ -113,7 +114,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
113
114
if self . cx . tcx . has_attr ( def_id, sym:: macro_export) {
114
115
if inserted. insert ( def_id) {
115
116
let item = self . cx . tcx . hir ( ) . expect_item ( local_def_id) ;
116
- top_level_module. items . push ( ( item, None ) ) ;
117
+ top_level_module. items . push ( ( item, None , None ) ) ;
117
118
}
118
119
}
119
120
}
@@ -155,6 +156,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
155
156
id : hir:: HirId ,
156
157
m : & ' tcx hir:: Mod < ' tcx > ,
157
158
name : Symbol ,
159
+ parent_id : Option < hir:: HirId > ,
158
160
) -> Module < ' tcx > {
159
161
let mut om = Module :: new ( name, id, m. spans . inner_span ) ;
160
162
let def_id = self . cx . tcx . hir ( ) . local_def_id ( id) . to_def_id ( ) ;
@@ -166,15 +168,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
166
168
if matches ! ( item. kind, hir:: ItemKind :: Use ( _, hir:: UseKind :: Glob ) ) {
167
169
continue ;
168
170
}
169
- self . visit_item ( item, None , & mut om) ;
171
+ self . visit_item ( item, None , & mut om, parent_id ) ;
170
172
}
171
173
for & i in m. item_ids {
172
174
let item = self . cx . tcx . hir ( ) . item ( i) ;
173
175
// To match the way import precedence works, visit glob imports last.
174
176
// Later passes in rustdoc will de-duplicate by name and kind, so if glob-
175
177
// imported items appear last, then they'll be the ones that get discarded.
176
178
if matches ! ( item. kind, hir:: ItemKind :: Use ( _, hir:: UseKind :: Glob ) ) {
177
- self . visit_item ( item, None , & mut om) ;
179
+ self . visit_item ( item, None , & mut om, parent_id ) ;
178
180
}
179
181
}
180
182
self . inside_public_path = orig_inside_public_path;
@@ -247,14 +249,14 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
247
249
let prev = mem:: replace ( & mut self . inlining , true ) ;
248
250
for & i in m. item_ids {
249
251
let i = self . cx . tcx . hir ( ) . item ( i) ;
250
- self . visit_item ( i, None , om) ;
252
+ self . visit_item ( i, None , om, Some ( id ) ) ;
251
253
}
252
254
self . inlining = prev;
253
255
true
254
256
}
255
257
Node :: Item ( it) if !glob => {
256
258
let prev = mem:: replace ( & mut self . inlining , true ) ;
257
- self . visit_item ( it, renamed, om) ;
259
+ self . visit_item ( it, renamed, om, Some ( id ) ) ;
258
260
self . inlining = prev;
259
261
true
260
262
}
@@ -275,6 +277,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
275
277
item : & ' tcx hir:: Item < ' _ > ,
276
278
renamed : Option < Symbol > ,
277
279
om : & mut Module < ' tcx > ,
280
+ parent_id : Option < hir:: HirId > ,
278
281
) {
279
282
debug ! ( "visiting item {:?}" , item) ;
280
283
let name = renamed. unwrap_or ( item. ident . name ) ;
@@ -330,7 +333,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
330
333
}
331
334
}
332
335
333
- om. items . push ( ( item, renamed) )
336
+ om. items . push ( ( item, renamed, parent_id ) )
334
337
}
335
338
hir:: ItemKind :: Macro ( ref macro_def, _) => {
336
339
// `#[macro_export] macro_rules!` items are handled separately in `visit()`,
@@ -349,11 +352,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
349
352
let nonexported = !self . cx . tcx . has_attr ( def_id, sym:: macro_export) ;
350
353
351
354
if is_macro_2_0 || nonexported || self . inlining {
352
- om. items . push ( ( item, renamed) ) ;
355
+ om. items . push ( ( item, renamed, None ) ) ;
353
356
}
354
357
}
355
358
hir:: ItemKind :: Mod ( ref m) => {
356
- om. mods . push ( self . visit_mod_contents ( item. hir_id ( ) , m, name) ) ;
359
+ om. mods . push ( self . visit_mod_contents ( item. hir_id ( ) , m, name, parent_id ) ) ;
357
360
}
358
361
hir:: ItemKind :: Fn ( ..)
359
362
| hir:: ItemKind :: ExternCrate ( ..)
@@ -364,19 +367,19 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
364
367
| hir:: ItemKind :: OpaqueTy ( ..)
365
368
| hir:: ItemKind :: Static ( ..)
366
369
| hir:: ItemKind :: Trait ( ..)
367
- | hir:: ItemKind :: TraitAlias ( ..) => om. items . push ( ( item, renamed) ) ,
370
+ | hir:: ItemKind :: TraitAlias ( ..) => om. items . push ( ( item, renamed, parent_id ) ) ,
368
371
hir:: ItemKind :: Const ( ..) => {
369
372
// Underscore constants do not correspond to a nameable item and
370
373
// so are never useful in documentation.
371
374
if name != kw:: Underscore {
372
- om. items . push ( ( item, renamed) ) ;
375
+ om. items . push ( ( item, renamed, parent_id ) ) ;
373
376
}
374
377
}
375
378
hir:: ItemKind :: Impl ( impl_) => {
376
379
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
377
380
// them up regardless of where they're located.
378
381
if !self . inlining && impl_. of_trait . is_none ( ) {
379
- om. items . push ( ( item, None ) ) ;
382
+ om. items . push ( ( item, None , None ) ) ;
380
383
}
381
384
}
382
385
}
0 commit comments