From 7e64cebf97df021b7ece9df435e748652e0b2e83 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 12 Dec 2022 12:46:11 -0700 Subject: [PATCH] rustdoc: stop treating everything in a trait item as a method This was added in 0b9b4b70683db6ef707755f520f139eb7b92a944 to fix the spacing on trait pages, but stopped being needed because 791f04e5a47ee78951552c7ed1545b2b01a44c74 stopped styling method-toggle. By only putting the method-toggle class on actual methods, the JS setting does the right thing. --- src/librustdoc/formats/item_type.rs | 3 +++ src/librustdoc/html/render/mod.rs | 3 +-- src/librustdoc/html/render/print_item.rs | 3 ++- src/test/rustdoc/toggle-trait-fn.rs | 7 +++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index f21e60a64e0..2f1f4cbf359 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -177,6 +177,9 @@ impl ItemType { ItemType::TraitAlias => "traitalias", } } + pub(crate) fn is_method(&self) -> bool { + matches!(*self, ItemType::Method | ItemType::TyMethod) + } } impl fmt::Display for ItemType { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 36d15ec3b86..80fbe9c1f06 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1512,8 +1512,7 @@ fn render_impl( let toggled = !doc_buffer.is_empty(); if toggled { - let method_toggle_class = - if item_type == ItemType::Method { " method-toggle" } else { "" }; + let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" }; write!(w, "
", method_toggle_class); } match &*item.kind { diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index acbe3f22889..a7b57c373e3 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -732,7 +732,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: document(&mut content, cx, m, Some(t), HeadingOffset::H5); let toggled = !content.is_empty(); if toggled { - write!(w, "
"); + let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" }; + write!(w, "
"); } write!(w, "
", id); render_rightside(w, cx, m, t, RenderMode::Normal); diff --git a/src/test/rustdoc/toggle-trait-fn.rs b/src/test/rustdoc/toggle-trait-fn.rs index e41422ce7c5..0a1f088b9ab 100644 --- a/src/test/rustdoc/toggle-trait-fn.rs +++ b/src/test/rustdoc/toggle-trait-fn.rs @@ -4,6 +4,8 @@ // summary. Trait methods with no documentation should not be wrapped. // // @has foo/trait.Foo.html +// @has - '//details[@class="rustdoc-toggle"]//summary//h4[@class="code-header"]' 'type Item' +// @!has - '//details[@class="rustdoc-toggle"]//summary//h4[@class="code-header"]' 'type Item2' // @has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'is_documented()' // @!has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'not_documented()' // @has - '//details[@class="rustdoc-toggle method-toggle"]//*[@class="docblock"]' 'is_documented is documented' @@ -11,6 +13,11 @@ // @!has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'not_documented_optional()' // @has - '//details[@class="rustdoc-toggle method-toggle"]//*[@class="docblock"]' 'is_documented_optional is documented' pub trait Foo { + /// is documented + type Item; + + type Item2; + fn not_documented(); /// is_documented is documented