Skip to content

Commit d1ad40e

Browse files
Fix rendering of reexported macros 2.0
1 parent c5e344f commit d1ad40e

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -546,17 +546,35 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
546546
fn build_macro(cx: &mut DocContext<'_>, did: DefId, name: Symbol) -> clean::ItemKind {
547547
let imported_from = cx.tcx.crate_name(did.krate);
548548
match cx.enter_resolver(|r| r.cstore().load_macro_untracked(did, cx.sess())) {
549-
LoadedMacro::MacroDef(def, _) => {
550-
if let ast::ItemKind::MacroDef(ref def) = def.kind {
549+
LoadedMacro::MacroDef(item_def, _) => {
550+
if let ast::ItemKind::MacroDef(ref def) = item_def.kind {
551551
let tts: Vec<_> = def.body.inner_tokens().into_trees().collect();
552552
let matchers = tts.chunks(4).map(|arm| &arm[0]);
553-
554-
let source = format!(
555-
"macro_rules! {} {{\n{}}}",
556-
name,
557-
utils::render_macro_arms(matchers, ";")
558-
);
559-
553+
let source = if def.macro_rules {
554+
format!(
555+
"macro_rules! {} {{\n{}}}",
556+
name,
557+
utils::render_macro_arms(matchers, ";")
558+
)
559+
} else {
560+
let vis = item_def.vis.clean(cx);
561+
562+
if matchers.len() <= 1 {
563+
format!(
564+
"{}macro {}{} {{\n ...\n}}",
565+
vis.to_src_with_space(cx.tcx, did),
566+
name,
567+
matchers.map(utils::render_macro_matcher).collect::<String>(),
568+
)
569+
} else {
570+
format!(
571+
"{}macro {} {{\n{}}}",
572+
vis.to_src_with_space(cx.tcx, did),
573+
name,
574+
utils::render_macro_arms(matchers, ";"),
575+
)
576+
}
577+
};
560578
clean::MacroItem(clean::Macro { source, imported_from: Some(imported_from) })
561579
} else {
562580
unreachable!()

src/librustdoc/clean/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ crate mod types;
1010
crate mod utils;
1111

1212
use rustc_ast as ast;
13+
use rustc_ast_lowering::ResolverAstLowering;
1314
use rustc_attr as attr;
1415
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1516
use rustc_hir as hir;
@@ -1696,6 +1697,23 @@ impl Clean<Visibility> for hir::Visibility<'_> {
16961697
}
16971698
}
16981699

1700+
impl Clean<Visibility> for ast::Visibility {
1701+
fn clean(&self, cx: &mut DocContext<'_>) -> Visibility {
1702+
match self.kind {
1703+
ast::VisibilityKind::Public => Visibility::Public,
1704+
ast::VisibilityKind::Inherited => Visibility::Inherited,
1705+
ast::VisibilityKind::Crate(_) => {
1706+
let krate = DefId::local(CRATE_DEF_INDEX);
1707+
Visibility::Restricted(krate)
1708+
}
1709+
ast::VisibilityKind::Restricted { id, .. } => {
1710+
let did = cx.enter_resolver(|r| r.local_def_id(id)).to_def_id();
1711+
Visibility::Restricted(did)
1712+
}
1713+
}
1714+
}
1715+
}
1716+
16991717
impl Clean<Visibility> for ty::Visibility {
17001718
fn clean(&self, _cx: &mut DocContext<'_>) -> Visibility {
17011719
match *self {

src/librustdoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern crate tracing;
3131
// Dependencies listed in Cargo.toml do not need `extern crate`.
3232

3333
extern crate rustc_ast;
34+
extern crate rustc_ast_lowering;
3435
extern crate rustc_ast_pretty;
3536
extern crate rustc_attr;
3637
extern crate rustc_data_structures;

0 commit comments

Comments
 (0)