Skip to content

Commit

Permalink
rustdoc: Clean Visibility outside of display_macro_source
Browse files Browse the repository at this point in the history
This change should make the code a bit clearer and easier to change.
  • Loading branch information
camelid committed Nov 17, 2021
1 parent 41301c3 commit 7a7698a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
9 changes: 2 additions & 7 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -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!()
Expand Down
9 changes: 6 additions & 3 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -1792,9 +1792,12 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
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()
Expand Down
4 changes: 1 addition & 3 deletions src/librustdoc/clean/utils.rs
Expand Up @@ -529,7 +529,7 @@ pub(super) fn display_macro_source(
name: Symbol,
def: &ast::MacroDef,
def_id: DefId,
vis: impl Clean<Visibility>,
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.
Expand All @@ -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}}",
Expand Down

0 comments on commit 7a7698a

Please sign in to comment.