Skip to content

Commit 031f293

Browse files
authored
Unrolled build for #144700
Rollup merge of #144700 - aDotInTheVoid:macro-rules-for-macro-fools, r=GuillaumeGomez rustdoc-json: Move `#[macro_export]` from `Other` to it's own variant Followup to #142936. cargo-semver-checks [cares about this attribute](https://github.com/obi1kenobi/trustfall-rustdoc-adapter/blob/4a0d1b0ca19b3115bb65d0b6695c388d7f474ac9/src/visibility_tracker.rs#L459-L476), and it wasn't included in the initial PR for structured attributes CC `@obi1kenobi.` r? `@GuillaumeGomez`
2 parents 6c02dd4 + a33e084 commit 031f293

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/librustdoc/json/conversions.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,12 @@ fn maybe_from_hir_attr(
908908
hir::Attribute::Parsed(kind) => kind,
909909

910910
hir::Attribute::Unparsed(_) => {
911-
// FIXME: We should handle `#[doc(hidden)]`.
912-
return Some(other_attr(tcx, attr));
911+
return Some(if attr.has_name(sym::macro_export) {
912+
Attribute::MacroExport
913+
// FIXME: We should handle `#[doc(hidden)]`.
914+
} else {
915+
other_attr(tcx, attr)
916+
});
913917
}
914918
};
915919

src/rustdoc-json-types/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
3737
// will instead cause conflicts. See #94591 for more. (This paragraph and the "Latest feature" line
3838
// are deliberately not in a doc comment, because they need not be in public docs.)
3939
//
40-
// Latest feature: Structured Attributes
41-
pub const FORMAT_VERSION: u32 = 54;
40+
// Latest feature: Add Attribute::MacroUse
41+
pub const FORMAT_VERSION: u32 = 55;
4242

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

219+
/// `#[macro_export]`
220+
MacroExport,
221+
219222
/// `#[export_name = "name"]`
220223
ExportName(String),
221224

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//@ compile-flags: --document-private-items
2+
3+
//@ set exported_id = "$.index[?(@.name=='exported')].id"
4+
//@ is "$.index[?(@.name=='exported')].attrs" '["macro_export"]'
5+
//@ is "$.index[?(@.name=='exported')].visibility" '"public"'
6+
7+
#[macro_export]
8+
macro_rules! exported {
9+
() => {};
10+
}
11+
12+
//@ set not_exported_id = "$.index[?(@.name=='not_exported')].id"
13+
//@ is "$.index[?(@.name=='not_exported')].attrs" []
14+
//@ is "$.index[?(@.name=='not_exported')].visibility" '"crate"'
15+
macro_rules! not_exported {
16+
() => {};
17+
}
18+
19+
//@ set module_id = "$.index[?(@.name=='module')].id"
20+
pub mod module {
21+
//@ set exported_from_mod_id = "$.index[?(@.name=='exported_from_mod')].id"
22+
//@ is "$.index[?(@.name=='exported_from_mod')].attrs" '["macro_export"]'
23+
//@ is "$.index[?(@.name=='exported_from_mod')].visibility" '"public"'
24+
#[macro_export]
25+
macro_rules! exported_from_mod {
26+
() => {};
27+
}
28+
29+
//@ set not_exported_from_mod_id = "$.index[?(@.name=='not_exported_from_mod')].id"
30+
//@ is "$.index[?(@.name=='not_exported_from_mod')].attrs" []
31+
//@ is "$.index[?(@.name=='not_exported_from_mod')].visibility" '"crate"'
32+
macro_rules! not_exported_from_mod {
33+
() => {};
34+
}
35+
}
36+
// The non-exported macro's are left in place, but the #[macro_export]'d ones
37+
// are moved to the crate root.
38+
39+
//@ is "$.index[?(@.name=='module')].inner.module.items[*]" $not_exported_from_mod_id
40+
//@ ismany "$.index[?(@.name=='macro_export')].inner.module.items[*]" $exported_id $not_exported_id $module_id $exported_from_mod_id

0 commit comments

Comments
 (0)