@@ -41,6 +41,7 @@ type Attrs<'hir> = rustc_middle::ty::Attributes<'hir>;
41
41
crate fn try_inline (
42
42
cx : & mut DocContext < ' _ > ,
43
43
parent_module : DefId ,
44
+ import_def_id : Option < DefId > ,
44
45
res : Res ,
45
46
name : Symbol ,
46
47
attrs : Option < Attrs < ' _ > > ,
@@ -108,7 +109,7 @@ crate fn try_inline(
108
109
clean:: ConstantItem ( build_const ( cx, did) )
109
110
}
110
111
Res :: Def ( DefKind :: Macro ( kind) , did) => {
111
- let mac = build_macro ( cx, did, name) ;
112
+ let mac = build_macro ( cx, did, name, import_def_id ) ;
112
113
113
114
let type_kind = match kind {
114
115
MacroKind :: Bang => ItemType :: Macro ,
@@ -123,14 +124,13 @@ crate fn try_inline(
123
124
124
125
let ( attrs, cfg) = merge_attrs ( cx, Some ( parent_module) , load_attrs ( cx, did) , attrs_clone) ;
125
126
cx. inlined . insert ( did. into ( ) ) ;
126
- ret. push ( clean:: Item :: from_def_id_and_attrs_and_parts (
127
- did,
128
- Some ( name) ,
129
- kind,
130
- box attrs,
131
- cx,
132
- cfg,
133
- ) ) ;
127
+ let mut item =
128
+ clean:: Item :: from_def_id_and_attrs_and_parts ( did, Some ( name) , kind, box attrs, cx, cfg) ;
129
+ if let Some ( import_def_id) = import_def_id {
130
+ // The visibility needs to reflect the one from the reexport and not from the "source" DefId.
131
+ item. visibility = cx. tcx . visibility ( import_def_id) . clean ( cx) ;
132
+ }
133
+ ret. push ( item) ;
134
134
Some ( ret)
135
135
}
136
136
@@ -509,7 +509,9 @@ fn build_module(
509
509
) ) ,
510
510
cfg : None ,
511
511
} ) ;
512
- } else if let Some ( i) = try_inline ( cx, did, item. res , item. ident . name , None , visited) {
512
+ } else if let Some ( i) =
513
+ try_inline ( cx, did, None , item. res , item. ident . name , None , visited)
514
+ {
513
515
items. extend ( i)
514
516
}
515
517
}
@@ -543,13 +545,24 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
543
545
}
544
546
}
545
547
546
- fn build_macro ( cx : & mut DocContext < ' _ > , def_id : DefId , name : Symbol ) -> clean:: ItemKind {
548
+ fn build_macro (
549
+ cx : & mut DocContext < ' _ > ,
550
+ def_id : DefId ,
551
+ name : Symbol ,
552
+ import_def_id : Option < DefId > ,
553
+ ) -> clean:: ItemKind {
547
554
let imported_from = cx. tcx . crate_name ( def_id. krate ) ;
548
555
match cx. enter_resolver ( |r| r. cstore ( ) . load_macro_untracked ( def_id, cx. sess ( ) ) ) {
549
556
LoadedMacro :: MacroDef ( item_def, _) => {
550
557
if let ast:: ItemKind :: MacroDef ( ref def) = item_def. kind {
551
558
clean:: MacroItem ( clean:: Macro {
552
- source : utils:: display_macro_source ( cx, name, def, def_id, item_def. vis ) ,
559
+ source : utils:: display_macro_source (
560
+ cx,
561
+ name,
562
+ def,
563
+ def_id,
564
+ cx. tcx . visibility ( import_def_id. unwrap_or ( def_id) ) ,
565
+ ) ,
553
566
imported_from : Some ( imported_from) ,
554
567
} )
555
568
} else {
0 commit comments