From 0c38bf9606522bb8f06246705703f651ea269520 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 15 Sep 2020 00:41:07 +0200 Subject: [PATCH] Remove suffix from duplicate members We use the HTML ID of a member element to get its name. If there are multiple members with the same type and name (e. g. from a Deref implementation), the ID has a suffix to make it unique. Previosuly, we just interpreted this suffix as part of the name. With this patch, we strip the suffix and only use the actual name. --- CHANGELOG.md | 4 ++++ src/parser/mod.rs | 11 +++++++++-- .../snapshots/output__1.40.0_struct_anyhow_error.snap | 8 ++++---- .../snapshots/output__1.41.1_struct_anyhow_error.snap | 8 ++++---- .../snapshots/output__1.42.0_struct_anyhow_error.snap | 8 ++++---- .../snapshots/output__1.43.1_struct_anyhow_error.snap | 8 ++++---- .../snapshots/output__1.44.1_struct_anyhow_error.snap | 8 ++++---- .../snapshots/output__1.45.2_struct_anyhow_error.snap | 8 ++++---- .../snapshots/output__1.46.0_struct_anyhow_error.snap | 6 +++--- 9 files changed, 40 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35255ab..d35bff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ SPDX-License-Identifier: MIT # Changelog for rusty-man +# Unreleased + +- Remove suffix from duplicate members (e. g. from Deref implementations). + ## v0.3.0 (2020-09-11) This minor release adds support for Rust 1.46.0 and significantly improves the diff --git a/src/parser/mod.rs b/src/parser/mod.rs index d14b45d..25fee96 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -279,8 +279,15 @@ const MODULE_MEMBER_TYPES: &[doc::ItemType] = &[ ]; fn get_id_part(node: &kuchiki::NodeRef, i: usize) -> Option { - node.get_attribute("id") - .and_then(|s| s.splitn(2, '.').nth(i).map(ToOwned::to_owned)) + // id of format . (or .- for name collisions) + if let Some(id) = node.get_attribute("id") { + id.splitn(2, '.') + .nth(i) + .and_then(|s| s.splitn(2, '-').next()) + .map(ToOwned::to_owned) + } else { + None + } } fn get_fields( diff --git a/tests/snapshots/output__1.40.0_struct_anyhow_error.snap b/tests/snapshots/output__1.40.0_struct_anyhow_error.snap index c51a461..7a936ab 100644 --- a/tests/snapshots/output__1.40.0_struct_anyhow_error.snap +++ b/tests/snapshots/output__1.40.0_struct_anyhow_error.snap @@ -1,6 +1,6 @@ --- source: tests/output.rs -expression: "get_stdout(path, &[item])" +expression: "get_stdout(path, &[\"anyhow::Error\"])" --- anyhow Struct anyhow::Error rusty-man @@ -239,21 +239,21 @@ METHODS Downcast this error object by mutable reference. Methods from Deref - is-1 + is pub fn is(&self) -> bool where     T: 'static + Error, Returns `true` if the boxed type is the same as `T` - downcast_ref-1 + downcast_ref pub fn downcast_ref(&self) -> Option<&T> where     T: 'static + Error, Returns some reference to the boxed value if it is of type `T`, or `None` if it isn't. - downcast_mut-1 + downcast_mut pub fn downcast_mut(&mut self) -> Option<&mut T> where     T: 'static + Error, diff --git a/tests/snapshots/output__1.41.1_struct_anyhow_error.snap b/tests/snapshots/output__1.41.1_struct_anyhow_error.snap index c51a461..7a936ab 100644 --- a/tests/snapshots/output__1.41.1_struct_anyhow_error.snap +++ b/tests/snapshots/output__1.41.1_struct_anyhow_error.snap @@ -1,6 +1,6 @@ --- source: tests/output.rs -expression: "get_stdout(path, &[item])" +expression: "get_stdout(path, &[\"anyhow::Error\"])" --- anyhow Struct anyhow::Error rusty-man @@ -239,21 +239,21 @@ METHODS Downcast this error object by mutable reference. Methods from Deref - is-1 + is pub fn is(&self) -> bool where     T: 'static + Error, Returns `true` if the boxed type is the same as `T` - downcast_ref-1 + downcast_ref pub fn downcast_ref(&self) -> Option<&T> where     T: 'static + Error, Returns some reference to the boxed value if it is of type `T`, or `None` if it isn't. - downcast_mut-1 + downcast_mut pub fn downcast_mut(&mut self) -> Option<&mut T> where     T: 'static + Error, diff --git a/tests/snapshots/output__1.42.0_struct_anyhow_error.snap b/tests/snapshots/output__1.42.0_struct_anyhow_error.snap index c51a461..7a936ab 100644 --- a/tests/snapshots/output__1.42.0_struct_anyhow_error.snap +++ b/tests/snapshots/output__1.42.0_struct_anyhow_error.snap @@ -1,6 +1,6 @@ --- source: tests/output.rs -expression: "get_stdout(path, &[item])" +expression: "get_stdout(path, &[\"anyhow::Error\"])" --- anyhow Struct anyhow::Error rusty-man @@ -239,21 +239,21 @@ METHODS Downcast this error object by mutable reference. Methods from Deref - is-1 + is pub fn is(&self) -> bool where     T: 'static + Error, Returns `true` if the boxed type is the same as `T` - downcast_ref-1 + downcast_ref pub fn downcast_ref(&self) -> Option<&T> where     T: 'static + Error, Returns some reference to the boxed value if it is of type `T`, or `None` if it isn't. - downcast_mut-1 + downcast_mut pub fn downcast_mut(&mut self) -> Option<&mut T> where     T: 'static + Error, diff --git a/tests/snapshots/output__1.43.1_struct_anyhow_error.snap b/tests/snapshots/output__1.43.1_struct_anyhow_error.snap index c51a461..7a936ab 100644 --- a/tests/snapshots/output__1.43.1_struct_anyhow_error.snap +++ b/tests/snapshots/output__1.43.1_struct_anyhow_error.snap @@ -1,6 +1,6 @@ --- source: tests/output.rs -expression: "get_stdout(path, &[item])" +expression: "get_stdout(path, &[\"anyhow::Error\"])" --- anyhow Struct anyhow::Error rusty-man @@ -239,21 +239,21 @@ METHODS Downcast this error object by mutable reference. Methods from Deref - is-1 + is pub fn is(&self) -> bool where     T: 'static + Error, Returns `true` if the boxed type is the same as `T` - downcast_ref-1 + downcast_ref pub fn downcast_ref(&self) -> Option<&T> where     T: 'static + Error, Returns some reference to the boxed value if it is of type `T`, or `None` if it isn't. - downcast_mut-1 + downcast_mut pub fn downcast_mut(&mut self) -> Option<&mut T> where     T: 'static + Error, diff --git a/tests/snapshots/output__1.44.1_struct_anyhow_error.snap b/tests/snapshots/output__1.44.1_struct_anyhow_error.snap index c51a461..7a936ab 100644 --- a/tests/snapshots/output__1.44.1_struct_anyhow_error.snap +++ b/tests/snapshots/output__1.44.1_struct_anyhow_error.snap @@ -1,6 +1,6 @@ --- source: tests/output.rs -expression: "get_stdout(path, &[item])" +expression: "get_stdout(path, &[\"anyhow::Error\"])" --- anyhow Struct anyhow::Error rusty-man @@ -239,21 +239,21 @@ METHODS Downcast this error object by mutable reference. Methods from Deref - is-1 + is pub fn is(&self) -> bool where     T: 'static + Error, Returns `true` if the boxed type is the same as `T` - downcast_ref-1 + downcast_ref pub fn downcast_ref(&self) -> Option<&T> where     T: 'static + Error, Returns some reference to the boxed value if it is of type `T`, or `None` if it isn't. - downcast_mut-1 + downcast_mut pub fn downcast_mut(&mut self) -> Option<&mut T> where     T: 'static + Error, diff --git a/tests/snapshots/output__1.45.2_struct_anyhow_error.snap b/tests/snapshots/output__1.45.2_struct_anyhow_error.snap index 903f5ed..72dd4b6 100644 --- a/tests/snapshots/output__1.45.2_struct_anyhow_error.snap +++ b/tests/snapshots/output__1.45.2_struct_anyhow_error.snap @@ -1,6 +1,6 @@ --- source: tests/output.rs -expression: "get_stdout(&[item])" +expression: "get_stdout(path, &[\"anyhow::Error\"])" --- anyhow Struct anyhow::Error rusty-man @@ -239,21 +239,21 @@ METHODS Downcast this error object by mutable reference. Methods from Deref - is-1 + is pub fn is(&self) -> bool where     T: 'static + Error, Returns `true` if the boxed type is the same as `T` - downcast_ref-1 + downcast_ref pub fn downcast_ref(&self) -> Option<&T> where     T: 'static + Error, Returns some reference to the boxed value if it is of type `T`, or `None` if it isn't. - downcast_mut-1 + downcast_mut pub fn downcast_mut(&mut self) -> Option<&mut T> where     T: 'static + Error, diff --git a/tests/snapshots/output__1.46.0_struct_anyhow_error.snap b/tests/snapshots/output__1.46.0_struct_anyhow_error.snap index 40598c8..7a936ab 100644 --- a/tests/snapshots/output__1.46.0_struct_anyhow_error.snap +++ b/tests/snapshots/output__1.46.0_struct_anyhow_error.snap @@ -239,21 +239,21 @@ METHODS Downcast this error object by mutable reference. Methods from Deref - is-1 + is pub fn is(&self) -> bool where     T: 'static + Error, Returns `true` if the boxed type is the same as `T` - downcast_ref-1 + downcast_ref pub fn downcast_ref(&self) -> Option<&T> where     T: 'static + Error, Returns some reference to the boxed value if it is of type `T`, or `None` if it isn't. - downcast_mut-1 + downcast_mut pub fn downcast_mut(&mut self) -> Option<&mut T> where     T: 'static + Error,