Fix trait implementation list for Rust 1.45

In older Rust versions, trait implementations were listed under the
heading with the id "implementations" and in the div with the id
"implementations-list".  Since Rust 1.45, the method heading has the id
"implementations" and the trait implementations have the ids
"trait-implementations" and "trait-implementations-list".

This patch updates the parser with these new IDs while also checking the
old IDs for older documentation.
This commit is contained in:
Robin Krahl 2020-07-27 16:01:03 +02:00
parent 3c06846a30
commit ef8f6fa365
No known key found for this signature in database
GPG Key ID: 8E9B0870524F69D8
2 changed files with 21 additions and 25 deletions

View File

@ -16,6 +16,7 @@ SPDX-License-Identifier: MIT
- Fix group and ID for typdef items. - Fix group and ID for typdef items.
- Extract the description of module items as HTML instead of plain text. - Extract the description of module items as HTML instead of plain text.
- Sort implementations alphabetically. - Sort implementations alphabetically.
- Fix list of trait implementations for Rust 1.45.
## v0.1.2 (2020-07-25) ## v0.1.2 (2020-07-25)

View File

@ -433,26 +433,22 @@ fn get_implementations(
) -> anyhow::Result<(doc::ItemType, Vec<doc::MemberGroup>)> { ) -> anyhow::Result<(doc::ItemType, Vec<doc::MemberGroup>)> {
let mut groups: Vec<doc::MemberGroup> = Vec::new(); let mut groups: Vec<doc::MemberGroup> = Vec::new();
if let Some(group) = let group_data = vec![
get_implementation_group(document, parent, "Trait Implementations", "implementations")? // Rust < 1.45
{ ("Trait Implementations", "implementations-list"),
groups.push(group); // Rust >= 1.45
} ("Trait Implementations", "trait-implementations-list"),
if let Some(group) = get_implementation_group( (
document, "Auto Trait Implementations",
parent, "synthetic-implementations-list",
"Auto Trait Implementations", ),
"synthetic-implementations", ("Blanket Implementations", "blanket-implementations-list"),
)? { ];
groups.push(group);
} for (title, id) in group_data {
if let Some(group) = get_implementation_group( if let Some(group) = get_implementation_group(document, parent, title, id)? {
document, groups.push(group);
parent, }
"Blanket Implementations",
"blanket-implementations",
)? {
groups.push(group);
} }
Ok((doc::ItemType::Impl, groups)) Ok((doc::ItemType::Impl, groups))
@ -462,15 +458,14 @@ fn get_implementation_group(
document: &kuchiki::NodeRef, document: &kuchiki::NodeRef,
parent: &doc::Item, parent: &doc::Item,
title: &str, title: &str,
id: &str, list_id: &str,
) -> anyhow::Result<Option<doc::MemberGroup>> { ) -> anyhow::Result<Option<doc::MemberGroup>> {
let ty = doc::ItemType::Impl; let ty = doc::ItemType::Impl;
let mut impls = MemberDocs::new(parent, ty); let mut impls = MemberDocs::new(parent, ty);
let heading = select_first(document, &format!("#{}", id))?; let list_div = select_first(document, &format!("#{}", list_id))?;
let next = heading.and_then(|n| n.as_node().next_sibling()); if let Some(list_div) = list_div {
if let Some(div) = next { for item in list_div.as_node().children() {
for item in div.children() {
if is_element(&item, &local_name!("h3")) && has_class(&item, "impl") { if is_element(&item, &local_name!("h3")) && has_class(&item, "impl") {
let code = item.first_child(); let code = item.first_child();
let a = code let a = code