Skip to content

Commit 7e64ceb

Browse files
committed
rustdoc: stop treating everything in a trait item as a method
This was added in 0b9b4b7 to fix the spacing on trait pages, but stopped being needed because 791f04e stopped styling method-toggle. By only putting the method-toggle class on actual methods, the JS setting does the right thing.
1 parent 37d7de3 commit 7e64ceb

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

Diff for: src/librustdoc/formats/item_type.rs

+3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ impl ItemType {
177177
ItemType::TraitAlias => "traitalias",
178178
}
179179
}
180+
pub(crate) fn is_method(&self) -> bool {
181+
matches!(*self, ItemType::Method | ItemType::TyMethod)
182+
}
180183
}
181184

182185
impl fmt::Display for ItemType {

Diff for: src/librustdoc/html/render/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,7 @@ fn render_impl(
15121512

15131513
let toggled = !doc_buffer.is_empty();
15141514
if toggled {
1515-
let method_toggle_class =
1516-
if item_type == ItemType::Method { " method-toggle" } else { "" };
1515+
let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" };
15171516
write!(w, "<details class=\"rustdoc-toggle{}\" open><summary>", method_toggle_class);
15181517
}
15191518
match &*item.kind {

Diff for: src/librustdoc/html/render/print_item.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
732732
document(&mut content, cx, m, Some(t), HeadingOffset::H5);
733733
let toggled = !content.is_empty();
734734
if toggled {
735-
write!(w, "<details class=\"rustdoc-toggle method-toggle\" open><summary>");
735+
let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" };
736+
write!(w, "<details class=\"rustdoc-toggle{method_toggle_class}\" open><summary>");
736737
}
737738
write!(w, "<section id=\"{}\" class=\"method has-srclink\">", id);
738739
render_rightside(w, cx, m, t, RenderMode::Normal);

Diff for: src/test/rustdoc/toggle-trait-fn.rs

+7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
// summary. Trait methods with no documentation should not be wrapped.
55
//
66
// @has foo/trait.Foo.html
7+
// @has - '//details[@class="rustdoc-toggle"]//summary//h4[@class="code-header"]' 'type Item'
8+
// @!has - '//details[@class="rustdoc-toggle"]//summary//h4[@class="code-header"]' 'type Item2'
79
// @has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'is_documented()'
810
// @!has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'not_documented()'
911
// @has - '//details[@class="rustdoc-toggle method-toggle"]//*[@class="docblock"]' 'is_documented is documented'
1012
// @has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'is_documented_optional()'
1113
// @!has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'not_documented_optional()'
1214
// @has - '//details[@class="rustdoc-toggle method-toggle"]//*[@class="docblock"]' 'is_documented_optional is documented'
1315
pub trait Foo {
16+
/// is documented
17+
type Item;
18+
19+
type Item2;
20+
1421
fn not_documented();
1522

1623
/// is_documented is documented

0 commit comments

Comments
 (0)