Skip to content

Reexported macros docs #107897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2206,10 +2206,12 @@ fn clean_maybe_renamed_item<'tcx>(
};

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let nonexported = !tcx.has_attr(def_id, sym::macro_export);

if is_macro_2_0 || nonexported || self.inlining {
self.add_to_current_mod(item, renamed, None);
self.add_to_current_mod(item, renamed, import_id);
}
}
hir::ItemKind::Mod(ref m) => {
Expand Down
23 changes: 23 additions & 0 deletions tests/rustdoc/reexport-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Ensure that macros are correctly reexported and that they get both the comment from the
// `pub use` and from the macro.

#![crate_name = "foo"]

// @has 'foo/macro.foo.html'
// @!has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'x y'
// @has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'y'
#[macro_use]
mod my_module {
/// y
#[macro_export]
macro_rules! foo {
() => ();
}
}

// @has 'foo/another_mod/macro.bar.html'
// @has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'x y'
pub mod another_mod {
/// x
pub use crate::foo as bar;
}