Skip to content

Commit fd9d8ae

Browse files
Fix link to attr/derive bang macros
1 parent 3cbcc53 commit fd9d8ae

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

src/librustdoc/formats/item_type.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ item_type! {
9999
// This number is reserved for use in JavaScript
100100
// Generic = 26,
101101
Attribute = 27,
102+
BangMacroAttribute = 28,
103+
BangMacroDerive = 29,
102104
}
103105

104106
impl<'a> From<&'a clean::Item> for ItemType {
@@ -128,10 +130,8 @@ impl<'a> From<&'a clean::Item> for ItemType {
128130
clean::ForeignFunctionItem(..) => ItemType::Function, // no ForeignFunction
129131
clean::ForeignStaticItem(..) => ItemType::Static, // no ForeignStatic
130132
clean::MacroItem(..) => ItemType::Macro,
131-
// Is this a good idea?
132-
clean::AttrMacroItem => ItemType::ProcAttribute,
133-
// Is this a good idea?
134-
clean::DeriveMacroItem => ItemType::ProcDerive,
133+
clean::AttrMacroItem => ItemType::BangMacroAttribute,
134+
clean::DeriveMacroItem => ItemType::BangMacroDerive,
135135
clean::PrimitiveItem(..) => ItemType::Primitive,
136136
clean::RequiredAssocConstItem(..)
137137
| clean::ProvidedAssocConstItem(..)
@@ -229,6 +229,8 @@ impl ItemType {
229229
ItemType::ProcDerive => "derive",
230230
ItemType::TraitAlias => "traitalias",
231231
ItemType::Attribute => "attribute",
232+
ItemType::BangMacroAttribute => "bang-macro-attribute",
233+
ItemType::BangMacroDerive => "bang-macro-derive",
232234
}
233235
}
234236
pub(crate) fn is_method(&self) -> bool {

src/librustdoc/html/render/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,8 +2610,8 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
26102610
ItemType::ForeignType => ItemSection::ForeignTypes,
26112611
ItemType::Keyword => ItemSection::Keywords,
26122612
ItemType::Attribute => ItemSection::Attributes,
2613-
ItemType::ProcAttribute => ItemSection::AttributeMacros,
2614-
ItemType::ProcDerive => ItemSection::DeriveMacros,
2613+
ItemType::ProcAttribute | ItemType::BangMacroAttribute => ItemSection::AttributeMacros,
2614+
ItemType::ProcDerive | ItemType::BangMacroDerive => ItemSection::DeriveMacros,
26152615
ItemType::TraitAlias => ItemSection::TraitAliases,
26162616
}
26172617
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ const itemTypes = [
120120
"traitalias", // 25
121121
"generic",
122122
"attribute",
123+
null, // bang macro attribute
124+
null, // bang macro derive
123125
];
124126

125127
// used for special search precedence
@@ -1640,7 +1642,7 @@ class DocSearch {
16401642
* ], [string]>}
16411643
*/
16421644
const raw = JSON.parse(encoded);
1643-
return {
1645+
const item = {
16441646
krate: raw[0],
16451647
ty: raw[1],
16461648
modulePath: raw[2] === 0 ? null : raw[2] - 1,
@@ -1650,6 +1652,13 @@ class DocSearch {
16501652
deprecated: raw[6] === 1 ? true : false,
16511653
associatedItemDisambiguator: raw.length === 7 ? null : raw[7],
16521654
};
1655+
if (item.ty === 28 || item.ty === 29) {
1656+
// "proc attribute" is 23, "proc derive" is 24 whereas "bang macro attribute" is 28 and
1657+
// "bang macro derive" is 29, so 5 of difference to go from the latter to the former.
1658+
item.ty -= 5;
1659+
item.isBangMacro = true;
1660+
}
1661+
return item;
16531662
}
16541663

16551664
/**
@@ -2146,7 +2155,7 @@ class DocSearch {
21462155
let displayPath;
21472156
let href;
21482157
let traitPath = null;
2149-
const type = itemTypes[item.ty];
2158+
const type = item.entry.isBangMacro ? "macro" : itemTypes[item.ty];
21502159
const name = item.name;
21512160
let path = item.modulePath;
21522161
let exactPath = item.exactModulePath;
@@ -3949,7 +3958,7 @@ class DocSearch {
39493958
* @param {Promise<rustdoc.PlainResultObject|null>[]} data
39503959
* @returns {AsyncGenerator<rustdoc.ResultObject, boolean>}
39513960
*/
3952-
const flush = async function* (data) {
3961+
const flush = async function*(data) {
39533962
const satr = sortAndTransformResults(
39543963
await Promise.all(data),
39553964
null,

src/librustdoc/json/conversions.rs

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

0 commit comments

Comments
 (0)