diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 4a8a316037961..bdc96cf3570f4 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -592,14 +592,9 @@ fn build_macro( match CStore::from_tcx(cx.tcx).load_macro_untracked(def_id, cx.sess()) { LoadedMacro::MacroDef(item_def, _) => { if let ast::ItemKind::MacroDef(ref def) = item_def.kind { + let vis = cx.tcx.visibility(import_def_id.unwrap_or(def_id)).clean(cx); clean::MacroItem(clean::Macro { - source: utils::display_macro_source( - cx, - name, - def, - def_id, - cx.tcx.visibility(import_def_id.unwrap_or(def_id)), - ), + source: utils::display_macro_source(cx, name, def, def_id, vis), }) } else { unreachable!() diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7040106568983..c527e7f97252a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1792,9 +1792,12 @@ impl Clean> for (&hir::Item<'_>, Option) { ItemKind::Fn(ref sig, ref generics, body_id) => { clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx) } - ItemKind::Macro(ref macro_def) => MacroItem(Macro { - source: display_macro_source(cx, name, macro_def, def_id, item.vis), - }), + ItemKind::Macro(ref macro_def) => { + let vis = item.vis.clean(cx); + MacroItem(Macro { + source: display_macro_source(cx, name, macro_def, def_id, vis), + }) + } ItemKind::Trait(is_auto, unsafety, ref generics, bounds, item_ids) => { let items = item_ids .iter() diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 2fa7efcc6509b..62a1569423234 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -529,7 +529,7 @@ pub(super) fn display_macro_source( name: Symbol, def: &ast::MacroDef, def_id: DefId, - vis: impl Clean, + vis: Visibility, ) -> String { let tts: Vec<_> = def.body.inner_tokens().into_trees().collect(); // Extract the spans of all matchers. They represent the "interface" of the macro. @@ -538,8 +538,6 @@ pub(super) fn display_macro_source( if def.macro_rules { format!("macro_rules! {} {{\n{}}}", name, render_macro_arms(matchers, ";")) } else { - let vis = vis.clean(cx); - if matchers.len() <= 1 { format!( "{}macro {}{} {{\n ...\n}}",