@@ -41,6 +41,7 @@ type Attrs<'hir> = rustc_middle::ty::Attributes<'hir>;
4141crate fn try_inline (
4242 cx : & mut DocContext < ' _ > ,
4343 parent_module : DefId ,
44+ import_def_id : Option < DefId > ,
4445 res : Res ,
4546 name : Symbol ,
4647 attrs : Option < Attrs < ' _ > > ,
@@ -108,7 +109,7 @@ crate fn try_inline(
108109 clean:: ConstantItem ( build_const ( cx, did) )
109110 }
110111 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 ) ;
112113
113114 let type_kind = match kind {
114115 MacroKind :: Bang => ItemType :: Macro ,
@@ -123,14 +124,13 @@ crate fn try_inline(
123124
124125 let ( attrs, cfg) = merge_attrs ( cx, Some ( parent_module) , load_attrs ( cx, did) , attrs_clone) ;
125126 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) ;
134134 Some ( ret)
135135}
136136
@@ -509,7 +509,9 @@ fn build_module(
509509 ) ) ,
510510 cfg : None ,
511511 } ) ;
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+ {
513515 items. extend ( i)
514516 }
515517 }
@@ -543,13 +545,24 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
543545 }
544546}
545547
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 {
547554 let imported_from = cx. tcx . crate_name ( def_id. krate ) ;
548555 match cx. enter_resolver ( |r| r. cstore ( ) . load_macro_untracked ( def_id, cx. sess ( ) ) ) {
549556 LoadedMacro :: MacroDef ( item_def, _) => {
550557 if let ast:: ItemKind :: MacroDef ( ref def) = item_def. kind {
551558 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+ ) ,
553566 imported_from : Some ( imported_from) ,
554567 } )
555568 } else {
0 commit comments