mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 18:15:07 +03:00
Change HTML IDs for attribute macros and attributes
Rename `ItemType::BangMacro*` into `ItemType::DeclMacro*` Rename `isBangMacro` field into `forceMacroHref`
This commit is contained in:
@@ -770,8 +770,8 @@ pub(crate) fn type_(&self) -> ItemType {
|
||||
pub(crate) fn types(&self) -> impl Iterator<Item = ItemType> {
|
||||
if let ItemKind::MacroItem(_, macro_kinds) = self.kind {
|
||||
Either::Right(macro_kinds.iter().map(|kind| match kind {
|
||||
MacroKinds::ATTR => ItemType::BangMacroAttribute,
|
||||
MacroKinds::DERIVE => ItemType::BangMacroDerive,
|
||||
MacroKinds::ATTR => ItemType::DeclMacroAttribute,
|
||||
MacroKinds::DERIVE => ItemType::DeclMacroDerive,
|
||||
MacroKinds::BANG => ItemType::Macro,
|
||||
_ => panic!("unsupported macro kind {kind:?}"),
|
||||
}))
|
||||
|
||||
@@ -105,8 +105,8 @@ fn visit_u64<E: de::Error>(self, v: u64) -> Result<ItemType, E> {
|
||||
// distinction because they will point to a `macro.[name].html` file and not
|
||||
// `[attr|derive].[name].html` file, so the link generation needs to take it into account while
|
||||
// still having the filtering working as expected.
|
||||
BangMacroAttribute = 28,
|
||||
BangMacroDerive = 29,
|
||||
DeclMacroAttribute = 28,
|
||||
DeclMacroDerive = 29,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a clean::Item> for ItemType {
|
||||
@@ -226,8 +226,8 @@ pub(crate) fn as_str(&self) -> &'static str {
|
||||
ItemType::AssocConst => "associatedconstant",
|
||||
ItemType::ForeignType => "foreigntype",
|
||||
ItemType::Keyword => "keyword",
|
||||
ItemType::ProcAttribute | ItemType::BangMacroAttribute => "attr",
|
||||
ItemType::ProcDerive | ItemType::BangMacroDerive => "derive",
|
||||
ItemType::ProcAttribute | ItemType::DeclMacroAttribute => "attr",
|
||||
ItemType::ProcDerive | ItemType::DeclMacroDerive => "derive",
|
||||
ItemType::TraitAlias => "traitalias",
|
||||
ItemType::Attribute => "attribute",
|
||||
}
|
||||
|
||||
@@ -543,10 +543,10 @@ fn add_item_entry(&mut self, item_type: ItemType, new_url: String, name: String)
|
||||
ItemType::TypeAlias => self.type_aliases.insert(ItemEntry::new(new_url, name)),
|
||||
ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
|
||||
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
|
||||
ItemType::ProcAttribute | ItemType::BangMacroAttribute => {
|
||||
ItemType::ProcAttribute | ItemType::DeclMacroAttribute => {
|
||||
self.attribute_macros.insert(ItemEntry::new(new_url, name))
|
||||
}
|
||||
ItemType::ProcDerive | ItemType::BangMacroDerive => {
|
||||
ItemType::ProcDerive | ItemType::DeclMacroDerive => {
|
||||
self.derive_macros.insert(ItemEntry::new(new_url, name))
|
||||
}
|
||||
ItemType::TraitAlias => self.trait_aliases.insert(ItemEntry::new(new_url, name)),
|
||||
@@ -2605,8 +2605,8 @@ fn id(self) -> &'static str {
|
||||
Self::AssociatedConstants => "associated-consts",
|
||||
Self::ForeignTypes => "foreign-types",
|
||||
Self::Keywords => "keywords",
|
||||
Self::Attributes => "attributes",
|
||||
Self::AttributeMacros => "attribute-macros",
|
||||
Self::Attributes => "attribute-docs",
|
||||
Self::AttributeMacros => "attributes",
|
||||
Self::DeriveMacros => "derives",
|
||||
Self::TraitAliases => "trait-aliases",
|
||||
}
|
||||
@@ -2667,8 +2667,8 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
|
||||
ItemType::ForeignType => ItemSection::ForeignTypes,
|
||||
ItemType::Keyword => ItemSection::Keywords,
|
||||
ItemType::Attribute => ItemSection::Attributes,
|
||||
ItemType::ProcAttribute | ItemType::BangMacroAttribute => ItemSection::AttributeMacros,
|
||||
ItemType::ProcDerive | ItemType::BangMacroDerive => ItemSection::DeriveMacros,
|
||||
ItemType::ProcAttribute | ItemType::DeclMacroAttribute => ItemSection::AttributeMacros,
|
||||
ItemType::ProcDerive | ItemType::DeclMacroDerive => ItemSection::DeriveMacros,
|
||||
ItemType::TraitAlias => ItemSection::TraitAliases,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,8 +235,8 @@ fn deprecation_class_attr(is_deprecated: bool) -> &'static str {
|
||||
// we cheat by turning them into their "proc-macro equivalent".
|
||||
for type_ in item.types() {
|
||||
let type_ = match type_ {
|
||||
ItemType::BangMacroAttribute => ItemType::ProcAttribute,
|
||||
ItemType::BangMacroDerive => ItemType::ProcDerive,
|
||||
ItemType::DeclMacroAttribute => ItemType::ProcAttribute,
|
||||
ItemType::DeclMacroDerive => ItemType::ProcDerive,
|
||||
type_ => type_,
|
||||
};
|
||||
not_stripped_items.entry(type_).or_default().push((index, item));
|
||||
|
||||
@@ -793,8 +793,8 @@ function preLoadCss(cssUrl) {
|
||||
//block("associatedconstant", "associated-consts", "Associated Constants");
|
||||
block("foreigntype", "foreign-types", "Foreign Types");
|
||||
block("keyword", "keywords", "Keywords");
|
||||
block("attribute", "attributes", "Attributes");
|
||||
block("attr", "attribute-macros", "Attribute Macros");
|
||||
block("attribute", "attribute-docs", "Attributes");
|
||||
block("attr", "attributes", "Attribute Macros");
|
||||
block("derive", "derives", "Derive Macros");
|
||||
block("traitalias", "trait-aliases", "Trait Aliases");
|
||||
}
|
||||
|
||||
+1
-1
@@ -265,7 +265,7 @@ declare namespace rustdoc {
|
||||
* But the documentation lives in a single `macro.NAME.html` page, and
|
||||
* this boolean flag is used for generating that HREF.
|
||||
*/
|
||||
isBangMacro: boolean,
|
||||
forceMacroHref: boolean,
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1658,13 +1658,13 @@ class DocSearch {
|
||||
deprecated: raw[6] === 1 ? true : false,
|
||||
unstable: raw[7] === 1 ? true : false,
|
||||
associatedItemDisambiguatorOrExternCrateUrl: raw.length === 8 ? null : raw[8],
|
||||
isBangMacro: false,
|
||||
forceMacroHref: false,
|
||||
};
|
||||
if (item.ty === 28 || item.ty === 29) {
|
||||
// "proc attribute" is 23, "proc derive" is 24 whereas "bang macro attribute" is 28 and
|
||||
// "bang macro derive" is 29, so 5 of difference to go from the latter to the former.
|
||||
item.ty -= 5;
|
||||
item.isBangMacro = true;
|
||||
item.forceMacroHref = true;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
@@ -2164,7 +2164,7 @@ class DocSearch {
|
||||
let displayPath;
|
||||
let href;
|
||||
let traitPath = null;
|
||||
const type = item.entry && item.entry.isBangMacro ? "macro" : itemTypesName[item.ty];
|
||||
const type = item.entry && item.entry.forceMacroHref ? "macro" : itemTypesName[item.ty];
|
||||
const name = item.name;
|
||||
let path = item.modulePath;
|
||||
let exactPath = item.exactModulePath;
|
||||
|
||||
@@ -899,8 +899,8 @@ fn from_clean(kind: &ItemType, _renderer: &JsonRenderer<'_>) -> Self {
|
||||
Keyword => ItemKind::Keyword,
|
||||
Attribute => ItemKind::Attribute,
|
||||
TraitAlias => ItemKind::TraitAlias,
|
||||
ProcAttribute | BangMacroAttribute => ItemKind::ProcAttribute,
|
||||
ProcDerive | BangMacroDerive => ItemKind::ProcDerive,
|
||||
ProcAttribute | DeclMacroAttribute => ItemKind::ProcAttribute,
|
||||
ProcDerive | DeclMacroDerive => ItemKind::ProcDerive,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ define-function: (
|
||||
|
||||
// Now we check it's correctly listed in the crate page.
|
||||
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
|
||||
call-function: ("crate_page", {"name": "attr_macro", "section_id": "attribute-macros"})
|
||||
call-function: ("crate_page", {"name": "attr_macro", "section_id": "attributes"})
|
||||
call-function: ("crate_page", {"name": "derive_macro", "section_id": "derives"})
|
||||
// We also check we don't have duplicated sections.
|
||||
assert-count: ("//*[@id='main-content']/h2[text()='Attribute Macros']", 1)
|
||||
@@ -77,7 +77,7 @@ define-function: (
|
||||
|
||||
// And finally we check it's correctly listed in the "all items" page.
|
||||
go-to: "file://" + |DOC_PATH| + "/test_docs/all.html"
|
||||
call-function: ("all_items_page", {"name": "attr_macro", "section_id": "attribute-macros"})
|
||||
call-function: ("all_items_page", {"name": "attr_macro", "section_id": "attributes"})
|
||||
call-function: ("all_items_page", {"name": "derive_macro", "section_id": "derives"})
|
||||
|
||||
// We now check a macro with all 3 different kinds.
|
||||
|
||||
@@ -66,6 +66,15 @@ assert-css: (
|
||||
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
|
||||
)
|
||||
// attributes
|
||||
assert-css: (
|
||||
"#attribute-docs + .item-table dt a",
|
||||
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
|
||||
)
|
||||
assert-css: (
|
||||
"#attribute-docs + .item-table dd",
|
||||
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
|
||||
)
|
||||
// attribute macros
|
||||
assert-css: (
|
||||
"#attributes + .item-table dt a",
|
||||
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
|
||||
@@ -74,12 +83,3 @@ assert-css: (
|
||||
"#attributes + .item-table dd",
|
||||
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
|
||||
)
|
||||
// attribute macros
|
||||
assert-css: (
|
||||
"#attribute-macros + .item-table dt a",
|
||||
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
|
||||
)
|
||||
assert-css: (
|
||||
"#attribute-macros + .item-table dd",
|
||||
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
|
||||
)
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
#![feature(rustdoc_internals)]
|
||||
|
||||
//@ has foo/index.html '//h2[@id="attributes"]' 'Attributes'
|
||||
//@ has foo/index.html '//h2[@id="attribute-docs"]' 'Attributes'
|
||||
//@ has foo/index.html '//a[@href="attribute.no_mangle.html"]' 'no_mangle'
|
||||
//@ has foo/index.html '//div[@class="sidebar-elems"]//li/a' 'Attributes'
|
||||
//@ has foo/index.html '//div[@class="sidebar-elems"]//li/a/@href' '#attributes'
|
||||
//@ has foo/index.html '//div[@class="sidebar-elems"]//li/a/@href' '#attribute-docs'
|
||||
//@ has foo/attribute.no_mangle.html '//h1' 'Attribute no_mangle'
|
||||
//@ has foo/attribute.no_mangle.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
|
||||
//@ has foo/index.html '//a/@href' '../foo/index.html'
|
||||
|
||||
Reference in New Issue
Block a user