Skip to content

Commit 3073c7a

Browse files
authored
Rollup merge of rust-lang#56315 - weiznich:rustdoc_inline_macro_reexport, r=QuietMisdreavus
Rustdoc inline macro reexport Fixes rust-lang#56173 I assume this needs to have tests? Any pointers where these need to be added?
2 parents 1839c14 + 956b03f commit 3073c7a

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/librustdoc/visit_ast.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
100100
None);
101101
// attach the crate's exported macros to the top-level module:
102102
let macro_exports: Vec<_> =
103-
krate.exported_macros.iter().map(|def| self.visit_local_macro(def)).collect();
103+
krate.exported_macros.iter().map(|def| self.visit_local_macro(def, None)).collect();
104104
self.module.macros.extend(macro_exports);
105105
self.module.is_crate = true;
106106

@@ -376,6 +376,10 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
376376
});
377377
true
378378
}
379+
Node::MacroDef(def) if !glob => {
380+
om.macros.push(self.visit_local_macro(def, renamed));
381+
true
382+
}
379383
_ => false,
380384
};
381385
self.view_item_stack.remove(&def_node_id);
@@ -593,7 +597,11 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
593597
}
594598

595599
// convert each exported_macro into a doc item
596-
fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro {
600+
fn visit_local_macro(
601+
&self,
602+
def: &hir::MacroDef,
603+
renamed: Option<ast::Name>
604+
) -> Macro {
597605
debug!("visit_local_macro: {}", def.name);
598606
let tts = def.body.trees().collect::<Vec<_>>();
599607
// Extract the spans of all matchers. They represent the "interface" of the macro.
@@ -602,7 +610,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
602610
Macro {
603611
def_id: self.cx.tcx.hir.local_def_id(def.id),
604612
attrs: def.attrs.clone(),
605-
name: def.name,
613+
name: renamed.unwrap_or(def.name),
606614
whence: def.span,
607615
matchers,
608616
stab: self.stability(def.id),
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
/// docs for foo
13+
#[deprecated(since = "1.2.3", note = "text")]
14+
#[macro_export]
15+
macro_rules! foo {
16+
($($tt:tt)*) => {}
17+
}
18+
19+
// @has macro_by_example/macros/index.html
20+
pub mod macros {
21+
// @!has - 'pub use foo as bar;'
22+
// @has macro_by_example/macros/macro.bar.html
23+
// @has - '//*[@class="docblock"]' 'docs for foo'
24+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.2.3: text'
25+
// @has - '//a/@href' 'macro_by_example.rs.html#15-17'
26+
#[doc(inline)]
27+
pub use foo as bar;
28+
}

0 commit comments

Comments
 (0)