Skip to content

rustdoc-json: Move #[macro_export] from Other to it's own variant #144700

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 2 commits into from
Aug 1, 2025
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: 6 additions & 2 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,12 @@ fn maybe_from_hir_attr(
hir::Attribute::Parsed(kind) => kind,

hir::Attribute::Unparsed(_) => {
// FIXME: We should handle `#[doc(hidden)]`.
return Some(other_attr(tcx, attr));
return Some(if attr.has_name(sym::macro_export) {
Attribute::MacroExport
// FIXME: We should handle `#[doc(hidden)]`.
} else {
other_attr(tcx, attr)
});
}
};

Expand Down
7 changes: 5 additions & 2 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
// will instead cause conflicts. See #94591 for more. (This paragraph and the "Latest feature" line
// are deliberately not in a doc comment, because they need not be in public docs.)
//
// Latest feature: Structured Attributes
pub const FORMAT_VERSION: u32 = 54;
// Latest feature: Add Attribute::MacroUse
pub const FORMAT_VERSION: u32 = 55;

/// The root of the emitted JSON blob.
///
Expand Down Expand Up @@ -216,6 +216,9 @@ pub enum Attribute {
/// `#[must_use]`
MustUse { reason: Option<String> },

/// `#[macro_export]`
MacroExport,

/// `#[export_name = "name"]`
ExportName(String),

Expand Down
40 changes: 40 additions & 0 deletions tests/rustdoc-json/attrs/macro_export.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//@ compile-flags: --document-private-items

//@ set exported_id = "$.index[?(@.name=='exported')].id"
//@ is "$.index[?(@.name=='exported')].attrs" '["macro_export"]'
//@ is "$.index[?(@.name=='exported')].visibility" '"public"'

#[macro_export]
macro_rules! exported {
() => {};
}

//@ set not_exported_id = "$.index[?(@.name=='not_exported')].id"
//@ is "$.index[?(@.name=='not_exported')].attrs" []
//@ is "$.index[?(@.name=='not_exported')].visibility" '"crate"'
macro_rules! not_exported {
() => {};
}

//@ set module_id = "$.index[?(@.name=='module')].id"
pub mod module {
//@ set exported_from_mod_id = "$.index[?(@.name=='exported_from_mod')].id"
//@ is "$.index[?(@.name=='exported_from_mod')].attrs" '["macro_export"]'
//@ is "$.index[?(@.name=='exported_from_mod')].visibility" '"public"'
#[macro_export]
macro_rules! exported_from_mod {
() => {};
}

//@ set not_exported_from_mod_id = "$.index[?(@.name=='not_exported_from_mod')].id"
//@ is "$.index[?(@.name=='not_exported_from_mod')].attrs" []
//@ is "$.index[?(@.name=='not_exported_from_mod')].visibility" '"crate"'
macro_rules! not_exported_from_mod {
() => {};
}
}
// The non-exported macro's are left in place, but the #[macro_export]'d ones
// are moved to the crate root.

//@ is "$.index[?(@.name=='module')].inner.module.items[*]" $not_exported_from_mod_id
//@ ismany "$.index[?(@.name=='macro_export')].inner.module.items[*]" $exported_id $not_exported_id $module_id $exported_from_mod_id
Loading