Skip to content

Commit 1305119

Browse files
authored
Rollup merge of #107897 - GuillaumeGomez:reexported-macros-docs, r=notriddle
Reexported macros docs Part of #59368 (doesn't fix it, only improve the current situation a bit). Macros were not correctly handled in reexports and the reexport attributes were not merged with the item either. This PR fixes both. r? `@notriddle`
2 parents 4b7b569 + 295fd0d commit 1305119

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/librustdoc/clean/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2209,10 +2209,12 @@ fn clean_maybe_renamed_item<'tcx>(
22092209
};
22102210

22112211
let mut extra_attrs = Vec::new();
2212-
if let Some(hir::Node::Item(use_node)) =
2213-
import_id.and_then(|def_id| cx.tcx.hir().find_by_def_id(def_id))
2212+
if let Some(import_id) = import_id &&
2213+
let Some(hir::Node::Item(use_node)) = cx.tcx.hir().find_by_def_id(import_id)
22142214
{
2215-
// We get all the various imports' attributes.
2215+
// First, we add the attributes from the current import.
2216+
extra_attrs.extend_from_slice(inline::load_attrs(cx, import_id.to_def_id()));
2217+
// Then we get all the various imports' attributes.
22162218
get_all_import_attributes(use_node, cx.tcx, item.owner_id.def_id, &mut extra_attrs);
22172219
}
22182220

src/librustdoc/visit_ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
378378
let nonexported = !tcx.has_attr(def_id, sym::macro_export);
379379

380380
if is_macro_2_0 || nonexported || self.inlining {
381-
self.add_to_current_mod(item, renamed, None);
381+
self.add_to_current_mod(item, renamed, import_id);
382382
}
383383
}
384384
hir::ItemKind::Mod(ref m) => {

tests/rustdoc/reexport-macro.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Ensure that macros are correctly reexported and that they get both the comment from the
2+
// `pub use` and from the macro.
3+
4+
#![crate_name = "foo"]
5+
6+
// @has 'foo/macro.foo.html'
7+
// @!has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'x y'
8+
// @has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'y'
9+
#[macro_use]
10+
mod my_module {
11+
/// y
12+
#[macro_export]
13+
macro_rules! foo {
14+
() => ();
15+
}
16+
}
17+
18+
// @has 'foo/another_mod/macro.bar.html'
19+
// @has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'x y'
20+
pub mod another_mod {
21+
/// x
22+
pub use crate::foo as bar;
23+
}

0 commit comments

Comments
 (0)