Skip to content

Commit 6eca740

Browse files
Change HTML IDs for attribute macros and attributes
Rename `ItemType::BangMacro*` into `ItemType::DeclMacro*` Rename `isBangMacro` field into `forceMacroHref`
1 parent 09bab4f commit 6eca740

11 files changed

Lines changed: 30 additions & 30 deletions

File tree

src/librustdoc/clean/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,8 @@ impl Item {
757757
pub(crate) fn types(&self) -> impl Iterator<Item = ItemType> {
758758
if let ItemKind::MacroItem(_, macro_kinds) = self.kind {
759759
Either::Right(macro_kinds.iter().map(|kind| match kind {
760-
MacroKinds::ATTR => ItemType::BangMacroAttribute,
761-
MacroKinds::DERIVE => ItemType::BangMacroDerive,
760+
MacroKinds::ATTR => ItemType::DeclMacroAttribute,
761+
MacroKinds::DERIVE => ItemType::DeclMacroDerive,
762762
MacroKinds::BANG => ItemType::Macro,
763763
_ => panic!("unsupported macro kind {kind:?}"),
764764
}))

src/librustdoc/formats/item_type.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ item_type! {
105105
// distinction because they will point to a `macro.[name].html` file and not
106106
// `[attr|derive].[name].html` file, so the link generation needs to take it into account while
107107
// still having the filtering working as expected.
108-
BangMacroAttribute = 28,
109-
BangMacroDerive = 29,
108+
DeclMacroAttribute = 28,
109+
DeclMacroDerive = 29,
110110
}
111111

112112
impl<'a> From<&'a clean::Item> for ItemType {
@@ -226,8 +226,8 @@ impl ItemType {
226226
ItemType::AssocConst => "associatedconstant",
227227
ItemType::ForeignType => "foreigntype",
228228
ItemType::Keyword => "keyword",
229-
ItemType::ProcAttribute | ItemType::BangMacroAttribute => "attr",
230-
ItemType::ProcDerive | ItemType::BangMacroDerive => "derive",
229+
ItemType::ProcAttribute | ItemType::DeclMacroAttribute => "attr",
230+
ItemType::ProcDerive | ItemType::DeclMacroDerive => "derive",
231231
ItemType::TraitAlias => "traitalias",
232232
ItemType::Attribute => "attribute",
233233
}

src/librustdoc/html/render/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,10 @@ impl AllTypes {
543543
ItemType::TypeAlias => self.type_aliases.insert(ItemEntry::new(new_url, name)),
544544
ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
545545
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
546-
ItemType::ProcAttribute | ItemType::BangMacroAttribute => {
546+
ItemType::ProcAttribute | ItemType::DeclMacroAttribute => {
547547
self.attribute_macros.insert(ItemEntry::new(new_url, name))
548548
}
549-
ItemType::ProcDerive | ItemType::BangMacroDerive => {
549+
ItemType::ProcDerive | ItemType::DeclMacroDerive => {
550550
self.derive_macros.insert(ItemEntry::new(new_url, name))
551551
}
552552
ItemType::TraitAlias => self.trait_aliases.insert(ItemEntry::new(new_url, name)),
@@ -2605,8 +2605,8 @@ impl ItemSection {
26052605
Self::AssociatedConstants => "associated-consts",
26062606
Self::ForeignTypes => "foreign-types",
26072607
Self::Keywords => "keywords",
2608-
Self::Attributes => "attributes",
2609-
Self::AttributeMacros => "attribute-macros",
2608+
Self::Attributes => "attribute-docs",
2609+
Self::AttributeMacros => "attributes",
26102610
Self::DeriveMacros => "derives",
26112611
Self::TraitAliases => "trait-aliases",
26122612
}
@@ -2667,8 +2667,8 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
26672667
ItemType::ForeignType => ItemSection::ForeignTypes,
26682668
ItemType::Keyword => ItemSection::Keywords,
26692669
ItemType::Attribute => ItemSection::Attributes,
2670-
ItemType::ProcAttribute | ItemType::BangMacroAttribute => ItemSection::AttributeMacros,
2671-
ItemType::ProcDerive | ItemType::BangMacroDerive => ItemSection::DeriveMacros,
2670+
ItemType::ProcAttribute | ItemType::DeclMacroAttribute => ItemSection::AttributeMacros,
2671+
ItemType::ProcDerive | ItemType::DeclMacroDerive => ItemSection::DeriveMacros,
26722672
ItemType::TraitAlias => ItemSection::TraitAliases,
26732673
}
26742674
}

src/librustdoc/html/render/print_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
235235
// we cheat by turning them into their "proc-macro equivalent".
236236
for type_ in item.types() {
237237
let type_ = match type_ {
238-
ItemType::BangMacroAttribute => ItemType::ProcAttribute,
239-
ItemType::BangMacroDerive => ItemType::ProcDerive,
238+
ItemType::DeclMacroAttribute => ItemType::ProcAttribute,
239+
ItemType::DeclMacroDerive => ItemType::ProcDerive,
240240
type_ => type_,
241241
};
242242
not_stripped_items.entry(type_).or_default().push((index, item));

src/librustdoc/html/static/js/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,8 @@ function preLoadCss(cssUrl) {
793793
//block("associatedconstant", "associated-consts", "Associated Constants");
794794
block("foreigntype", "foreign-types", "Foreign Types");
795795
block("keyword", "keywords", "Keywords");
796-
block("attribute", "attributes", "Attributes");
797-
block("attr", "attribute-macros", "Attribute Macros");
796+
block("attribute", "attribute-docs", "Attributes");
797+
block("attr", "attributes", "Attribute Macros");
798798
block("derive", "derives", "Derive Macros");
799799
block("traitalias", "trait-aliases", "Trait Aliases");
800800
}

src/librustdoc/html/static/js/rustdoc.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ declare namespace rustdoc {
265265
* But the documentation lives in a single `macro.NAME.html` page, and
266266
* this boolean flag is used for generating that HREF.
267267
*/
268-
isBangMacro: boolean,
268+
forceMacroHref: boolean,
269269
}
270270

271271
/**

src/librustdoc/html/static/js/search.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,13 +1658,13 @@ class DocSearch {
16581658
deprecated: raw[6] === 1 ? true : false,
16591659
unstable: raw[7] === 1 ? true : false,
16601660
associatedItemDisambiguatorOrExternCrateUrl: raw.length === 8 ? null : raw[8],
1661-
isBangMacro: false,
1661+
forceMacroHref: false,
16621662
};
16631663
if (item.ty === 28 || item.ty === 29) {
16641664
// "proc attribute" is 23, "proc derive" is 24 whereas "bang macro attribute" is 28 and
16651665
// "bang macro derive" is 29, so 5 of difference to go from the latter to the former.
16661666
item.ty -= 5;
1667-
item.isBangMacro = true;
1667+
item.forceMacroHref = true;
16681668
}
16691669
return item;
16701670
}
@@ -2164,7 +2164,7 @@ class DocSearch {
21642164
let displayPath;
21652165
let href;
21662166
let traitPath = null;
2167-
const type = item.entry && item.entry.isBangMacro ? "macro" : itemTypesName[item.ty];
2167+
const type = item.entry && item.entry.forceMacroHref ? "macro" : itemTypesName[item.ty];
21682168
const name = item.name;
21692169
let path = item.modulePath;
21702170
let exactPath = item.exactModulePath;

src/librustdoc/json/conversions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ impl FromClean<ItemType> for ItemKind {
899899
Keyword => ItemKind::Keyword,
900900
Attribute => ItemKind::Attribute,
901901
TraitAlias => ItemKind::TraitAlias,
902-
ProcAttribute | BangMacroAttribute => ItemKind::ProcAttribute,
903-
ProcDerive | BangMacroDerive => ItemKind::ProcDerive,
902+
ProcAttribute | DeclMacroAttribute => ItemKind::ProcAttribute,
903+
ProcDerive | DeclMacroDerive => ItemKind::ProcDerive,
904904
}
905905
}
906906
}

tests/rustdoc-gui/attr-macros.goml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ define-function: (
5353

5454
// Now we check it's correctly listed in the crate page.
5555
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
56-
call-function: ("crate_page", {"name": "attr_macro", "section_id": "attribute-macros"})
56+
call-function: ("crate_page", {"name": "attr_macro", "section_id": "attributes"})
5757
call-function: ("crate_page", {"name": "derive_macro", "section_id": "derives"})
5858
// We also check we don't have duplicated sections.
5959
assert-count: ("//*[@id='main-content']/h2[text()='Attribute Macros']", 1)
@@ -77,7 +77,7 @@ define-function: (
7777

7878
// And finally we check it's correctly listed in the "all items" page.
7979
go-to: "file://" + |DOC_PATH| + "/test_docs/all.html"
80-
call-function: ("all_items_page", {"name": "attr_macro", "section_id": "attribute-macros"})
80+
call-function: ("all_items_page", {"name": "attr_macro", "section_id": "attributes"})
8181
call-function: ("all_items_page", {"name": "derive_macro", "section_id": "derives"})
8282

8383
// We now check a macro with all 3 different kinds.

tests/rustdoc-gui/module-items-font.goml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ assert-css: (
6767
)
6868
// attributes
6969
assert-css: (
70-
"#attributes + .item-table dt a",
70+
"#attribute-docs + .item-table dt a",
7171
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
7272
)
7373
assert-css: (
74-
"#attributes + .item-table dd",
74+
"#attribute-docs + .item-table dd",
7575
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
7676
)
7777
// attribute macros
7878
assert-css: (
79-
"#attribute-macros + .item-table dt a",
79+
"#attributes + .item-table dt a",
8080
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
8181
)
8282
assert-css: (
83-
"#attribute-macros + .item-table dd",
83+
"#attributes + .item-table dd",
8484
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
8585
)

0 commit comments

Comments
 (0)