Skip to content

Commit 7a7698a

Browse files
committed
rustdoc: Clean Visibility outside of display_macro_source
This change should make the code a bit clearer and easier to change.
1 parent 41301c3 commit 7a7698a

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/librustdoc/clean/inline.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -592,14 +592,9 @@ fn build_macro(
592592
match CStore::from_tcx(cx.tcx).load_macro_untracked(def_id, cx.sess()) {
593593
LoadedMacro::MacroDef(item_def, _) => {
594594
if let ast::ItemKind::MacroDef(ref def) = item_def.kind {
595+
let vis = cx.tcx.visibility(import_def_id.unwrap_or(def_id)).clean(cx);
595596
clean::MacroItem(clean::Macro {
596-
source: utils::display_macro_source(
597-
cx,
598-
name,
599-
def,
600-
def_id,
601-
cx.tcx.visibility(import_def_id.unwrap_or(def_id)),
602-
),
597+
source: utils::display_macro_source(cx, name, def, def_id, vis),
603598
})
604599
} else {
605600
unreachable!()

src/librustdoc/clean/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1792,9 +1792,12 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
17921792
ItemKind::Fn(ref sig, ref generics, body_id) => {
17931793
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
17941794
}
1795-
ItemKind::Macro(ref macro_def) => MacroItem(Macro {
1796-
source: display_macro_source(cx, name, macro_def, def_id, item.vis),
1797-
}),
1795+
ItemKind::Macro(ref macro_def) => {
1796+
let vis = item.vis.clean(cx);
1797+
MacroItem(Macro {
1798+
source: display_macro_source(cx, name, macro_def, def_id, vis),
1799+
})
1800+
}
17981801
ItemKind::Trait(is_auto, unsafety, ref generics, bounds, item_ids) => {
17991802
let items = item_ids
18001803
.iter()

src/librustdoc/clean/utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ pub(super) fn display_macro_source(
529529
name: Symbol,
530530
def: &ast::MacroDef,
531531
def_id: DefId,
532-
vis: impl Clean<Visibility>,
532+
vis: Visibility,
533533
) -> String {
534534
let tts: Vec<_> = def.body.inner_tokens().into_trees().collect();
535535
// Extract the spans of all matchers. They represent the "interface" of the macro.
@@ -538,8 +538,6 @@ pub(super) fn display_macro_source(
538538
if def.macro_rules {
539539
format!("macro_rules! {} {{\n{}}}", name, render_macro_arms(matchers, ";"))
540540
} else {
541-
let vis = vis.clean(cx);
542-
543541
if matchers.len() <= 1 {
544542
format!(
545543
"{}macro {}{} {{\n ...\n}}",

0 commit comments

Comments
 (0)