diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa9825..83b1fd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ SPDX-License-Identifier: MIT - Fix group and ID for typdef items. - Extract the description of module items as HTML instead of plain text. - Sort implementations alphabetically. + - Fix list of trait implementations for Rust 1.45. ## v0.1.2 (2020-07-25) diff --git a/src/parser.rs b/src/parser.rs index 92f55c9..caafdfc 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -433,26 +433,22 @@ fn get_implementations( ) -> anyhow::Result<(doc::ItemType, Vec)> { let mut groups: Vec = Vec::new(); - if let Some(group) = - get_implementation_group(document, parent, "Trait Implementations", "implementations")? - { - groups.push(group); - } - if let Some(group) = get_implementation_group( - document, - parent, - "Auto Trait Implementations", - "synthetic-implementations", - )? { - groups.push(group); - } - if let Some(group) = get_implementation_group( - document, - parent, - "Blanket Implementations", - "blanket-implementations", - )? { - groups.push(group); + let group_data = vec![ + // Rust < 1.45 + ("Trait Implementations", "implementations-list"), + // Rust >= 1.45 + ("Trait Implementations", "trait-implementations-list"), + ( + "Auto Trait Implementations", + "synthetic-implementations-list", + ), + ("Blanket Implementations", "blanket-implementations-list"), + ]; + + for (title, id) in group_data { + if let Some(group) = get_implementation_group(document, parent, title, id)? { + groups.push(group); + } } Ok((doc::ItemType::Impl, groups)) @@ -462,15 +458,14 @@ fn get_implementation_group( document: &kuchiki::NodeRef, parent: &doc::Item, title: &str, - id: &str, + list_id: &str, ) -> anyhow::Result> { let ty = doc::ItemType::Impl; 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(div) = next { - for item in div.children() { + if let Some(list_div) = list_div { + for item in list_div.as_node().children() { if is_element(&item, &local_name!("h3")) && has_class(&item, "impl") { let code = item.first_child(); let a = code