Skip to content

Commit 8369e78

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

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

src/librustdoc/formats/item_type.rs

Lines changed: 6 additions & 6 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(..)
@@ -225,8 +225,8 @@ impl ItemType {
225225
ItemType::AssocConst => "associatedconstant",
226226
ItemType::ForeignType => "foreigntype",
227227
ItemType::Keyword => "keyword",
228-
ItemType::ProcAttribute => "attr",
229-
ItemType::ProcDerive => "derive",
228+
ItemType::ProcAttribute | ItemType::BangMacroAttribute => "attr",
229+
ItemType::ProcDerive | ItemType::BangMacroDerive => "derive",
230230
ItemType::TraitAlias => "traitalias",
231231
ItemType::Attribute => "attribute",
232232
}

src/librustdoc/html/render/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,12 @@ impl AllTypes {
523523
ItemType::TypeAlias => self.type_aliases.insert(ItemEntry::new(new_url, name)),
524524
ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
525525
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
526-
ItemType::ProcAttribute => {
526+
ItemType::ProcAttribute | ItemType::BangMacroAttribute => {
527527
self.attribute_macros.insert(ItemEntry::new(new_url, name))
528528
}
529-
ItemType::ProcDerive => self.derive_macros.insert(ItemEntry::new(new_url, name)),
529+
ItemType::ProcDerive | ItemType::BangMacroDerive => {
530+
self.derive_macros.insert(ItemEntry::new(new_url, name))
531+
}
530532
ItemType::TraitAlias => self.trait_aliases.insert(ItemEntry::new(new_url, name)),
531533
_ => true,
532534
};
@@ -2610,8 +2612,8 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
26102612
ItemType::ForeignType => ItemSection::ForeignTypes,
26112613
ItemType::Keyword => ItemSection::Keywords,
26122614
ItemType::Attribute => ItemSection::Attributes,
2613-
ItemType::ProcAttribute => ItemSection::AttributeMacros,
2614-
ItemType::ProcDerive => ItemSection::DeriveMacros,
2615+
ItemType::ProcAttribute | ItemType::BangMacroAttribute => ItemSection::AttributeMacros,
2616+
ItemType::ProcDerive | ItemType::BangMacroDerive => ItemSection::DeriveMacros,
26152617
ItemType::TraitAlias => ItemSection::TraitAliases,
26162618
}
26172619
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ declare namespace rustdoc {
244244
traitParent: number?,
245245
deprecated: boolean,
246246
associatedItemDisambiguator: string?,
247+
isBangMacro: boolean,
247248
}
248249

249250
/**
@@ -300,7 +301,7 @@ declare namespace rustdoc {
300301

301302
type ItemType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
302303
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
303-
21 | 22 | 23 | 24 | 25 | 26;
304+
21 | 22 | 23 | 24 | 25 | 26 | 28 | 29;
304305

305306
/**
306307
* The viewmodel for the search engine results page.

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

Lines changed: 13 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,
@@ -1649,7 +1651,15 @@ class DocSearch {
16491651
traitParent: raw[5] === 0 ? null : raw[5] - 1,
16501652
deprecated: raw[6] === 1 ? true : false,
16511653
associatedItemDisambiguator: raw.length === 7 ? null : raw[7],
1654+
isBangMacro: false,
16521655
};
1656+
if (item.ty === 28 || item.ty === 29) {
1657+
// "proc attribute" is 23, "proc derive" is 24 whereas "bang macro attribute" is 28 and
1658+
// "bang macro derive" is 29, so 5 of difference to go from the latter to the former.
1659+
item.ty -= 5;
1660+
item.isBangMacro = true;
1661+
}
1662+
return item;
16531663
}
16541664

16551665
/**
@@ -2146,7 +2156,7 @@ class DocSearch {
21462156
let displayPath;
21472157
let href;
21482158
let traitPath = null;
2149-
const type = itemTypes[item.ty];
2159+
const type = item.entry && item.entry.isBangMacro ? "macro" : itemTypes[item.ty];
21502160
const name = item.name;
21512161
let path = item.modulePath;
21522162
let exactPath = item.exactModulePath;
@@ -3949,7 +3959,7 @@ class DocSearch {
39493959
* @param {Promise<rustdoc.PlainResultObject|null>[]} data
39503960
* @returns {AsyncGenerator<rustdoc.ResultObject, boolean>}
39513961
*/
3952-
const flush = async function* (data) {
3962+
const flush = async function*(data) {
39533963
const satr = sortAndTransformResults(
39543964
await Promise.all(data),
39553965
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)