Skip to content

Commit 10bafe1

Browse files
committed
Remove toggle for "undocumented items."
Per discussion in rust-lang#84326. For trait implementations, this was misleading: the items actually do have documentation (but it comes from the trait definition). For both trait implementations and trait implementors, this was redundant: in both of those cases, the items are default-hidden by different toggle at the level above. Update tests: Remove XPath selectors that over-specified on details tag, in cases that weren't testing toggles. Add an explicit test for toggles on methods. Rename item-hide-threshold to toggle-item-contents for consistency.
1 parent 84b1005 commit 10bafe1

File tree

8 files changed

+64
-54
lines changed

8 files changed

+64
-54
lines changed

src/librustdoc/html/render/mod.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -1650,16 +1650,10 @@ fn render_impl(
16501650
);
16511651
}
16521652
}
1653-
if toggled {
1654-
w.write_str("<div class=\"impl-items\">");
1655-
w.push_buffer(default_impl_items);
1656-
if trait_.is_some() && !impl_items.is_empty() {
1657-
w.write_str("<details class=\"undocumented\"><summary></summary>");
1658-
close_tags.insert_str(0, "</details>");
1659-
}
1660-
w.push_buffer(impl_items);
1661-
close_tags.insert_str(0, "</div>");
1662-
}
1653+
w.write_str("<div class=\"impl-items\">");
1654+
w.push_buffer(default_impl_items);
1655+
w.push_buffer(impl_items);
1656+
close_tags.insert_str(0, "</div>");
16631657
w.write_str(&close_tags);
16641658
}
16651659

src/test/rustdoc/assoc-consts.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,12 @@ impl Qux for Bar {
8888
/// Docs for QUX1 in impl.
8989
const QUX1: i8 = 5;
9090
// @has - '//*[@id="associatedconstant.QUX_DEFAULT0"]' 'const QUX_DEFAULT0: u16'
91-
// @!has - '//div[@class="impl-items"]/details[@open=""]//*[@class="docblock"]' "Docs for QUX_DEFAULT12 in trait."
92-
// @has - '//div[@class="impl-items"]/details//*[@class="docblock"]' "Docs for QUX_DEFAULT12 in trait."
91+
// @has - '//div[@class="impl-items"]//*[@class="docblock"]' "Docs for QUX_DEFAULT12 in trait."
9392
const QUX_DEFAULT0: u16 = 6;
9493
// @has - '//*[@id="associatedconstant.QUX_DEFAULT1"]' 'const QUX_DEFAULT1: i16'
9594
// @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT1 in impl."
9695
/// Docs for QUX_DEFAULT1 in impl.
9796
const QUX_DEFAULT1: i16 = 7;
9897
// @has - '//*[@id="associatedconstant.QUX_DEFAULT2"]' 'const QUX_DEFAULT2: u32'
99-
// @!has - '//div[@class="impl-items"]/details[@open=""]//*[@class="docblock"]' "Docs for QUX_DEFAULT2 in trait."
100-
// @has - '//div[@class="impl-items"]/details//*[@class="docblock"]' "Docs for QUX_DEFAULT2 in trait."
98+
// @has - '//div[@class="impl-items"]//*[@class="docblock"]' "Docs for QUX_DEFAULT2 in trait."
10199
}

src/test/rustdoc/inline_cross/assoc-items.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ extern crate assoc_items;
1616
// @has - '//*[@id="associatedconstant.ConstNoDefault"]' 'const ConstNoDefault: i16'
1717
// @has - '//*[@class="docblock"]' 'dox for ConstNoDefault'
1818
// @has - '//*[@id="associatedconstant.ConstWithDefault"]' 'const ConstWithDefault: u16'
19-
// @!has - '//details[@open=""]/details/div[@class="docblock"]' 'docs for ConstWithDefault'
20-
// @has - '//details/details/div[@class="docblock"]' 'docs for ConstWithDefault'
19+
// @has - '//div[@class="docblock"]' 'docs for ConstWithDefault'
2120
// @has - '//*[@id="associatedtype.TypeNoDefault"]' 'type TypeNoDefault = i32'
2221
// @has - '//*[@class="docblock"]' 'dox for TypeNoDefault'
2322
// @has - '//*[@id="associatedtype.TypeWithDefault"]' 'type TypeWithDefault = u32'
24-
// @!has - '//details[@open=""]/details/div[@class="docblock"]' 'docs for TypeWithDefault'
25-
// @has - '//details/details/div[@class="docblock"]' 'docs for TypeWithDefault'
23+
// @has - '//div[@class="docblock"]' 'docs for TypeWithDefault'
2624
// @has - '//*[@id="method.method_no_default"]' 'fn method_no_default()'
2725
// @has - '//*[@class="docblock"]' 'dox for method_no_default'
2826
// @has - '//*[@id="method.method_with_default"]' 'fn method_with_default()'
29-
// @!has - '//details[@open=""]/details/div[@class="docblock"]' 'docs for method_with_default'
30-
// @has - '//details/details/div[@class="docblock"]' 'docs for method_with_default'
27+
// @has - '//div[@class="docblock"]' 'docs for method_with_default'
3128
pub use assoc_items::MyStruct;
3229

3330
// @has foo/trait.MyTrait.html

src/test/rustdoc/inline_cross/impl-inline-without-trait.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ extern crate impl_inline_without_trait;
88

99
// @has 'foo/struct.MyStruct.html'
1010
// @has - '//*[@id="method.my_trait_method"]' 'fn my_trait_method()'
11-
// @!has - '//details[@open=""]/details/div[@class="docblock"]' 'docs for my_trait_method'
12-
// @has - '//details/details/div[@class="docblock"]' 'docs for my_trait_method'
11+
// @has - '//div[@class="docblock"]' 'docs for my_trait_method'
1312
pub use impl_inline_without_trait::MyStruct;

src/test/rustdoc/manual_impl.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ pub trait T {
2424
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait implementation.'
2525
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait a_method implementation.'
2626
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
27-
// @!has - '//div[@class="impl-items"]/details[@open=""]//div[@class="docblock"]' 'Docs associated with the trait b_method definition.'
28-
// @has - '//div[@class="impl-items"]/details//div[@class="docblock"]' 'Docs associated with the trait b_method definition.'
29-
// @!has - '//div[@class="impl-items"]/details[@open=""]//div[@class="docblock"]' 'Docs associated with the trait c_method definition.'
30-
// @has - '//div[@class="impl-items"]/details//div[@class="docblock"]' 'Docs associated with the trait c_method definition.'
27+
// @has - '//div[@class="impl-items"]//div[@class="docblock"]' 'Docs associated with the trait b_method definition.'
28+
// @has - '//div[@class="impl-items"]//div[@class="docblock"]' 'Docs associated with the trait c_method definition.'
3129
// @!has - '//*[@class="docblock"]' 'There is another line'
32-
// @!has - '//div[@class="impl-items"]/details[@open=""]//div[@class="docblock"]' 'Read more'
33-
// @has - '//div[@class="impl-items"]/details//div[@class="docblock"]' 'Read more'
30+
// @has - '//div[@class="impl-items"]//div[@class="docblock"]' 'Read more'
3431
pub struct S1(usize);
3532

3633
/// Docs associated with the S1 trait implementation.
@@ -45,10 +42,7 @@ impl T for S1 {
4542
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait implementation.'
4643
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait a_method implementation.'
4744
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait c_method implementation.'
48-
// @!has - '//details[open=""]/div[@class="docblock"]' 'Docs associated with the trait a_method definition.'
49-
// @!has - '//details[open=""]/div[@class="docblock"]' 'Docs associated with the trait c_method definition.'
50-
// @!has - '//div[@class="impl-items"]/details[@open=""]//div[@class="docblock"]' 'Docs associated with the trait b_method definition.'
51-
// @has - '//div[@class="impl-items"]/details//div[@class="docblock"]' 'Docs associated with the trait b_method definition.'
45+
// @has - '//div[@class="impl-items"]//div[@class="docblock"]' 'Docs associated with the trait b_method definition.'
5246
pub struct S2(usize);
5347

5448
/// Docs associated with the S2 trait implementation.
@@ -65,11 +59,9 @@ impl T for S2 {
6559
}
6660

6761
// @has manual_impl/struct.S3.html '//*[@class="trait"]' 'T'
68-
// @has - '//details/div[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
69-
// @!has - '//details[@open=""]/div[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
70-
// @has - '//details[@open=""]/div[@class="docblock"]' 'Docs associated with the S3 trait b_method implementation.'
71-
// @!has - '//div[@class="impl-items"]/details[@open=""]//div[@class="docblock"]' 'Docs associated with the trait a_method definition.'
72-
// @has - '//div[@class="impl-items"]/details//div[@class="docblock"]' 'Docs associated with the trait a_method definition.'
62+
// @has - '//div[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
63+
// @has - '//div[@class="docblock"]' 'Docs associated with the S3 trait b_method implementation.'
64+
// @has - '//div[@class="impl-items"]//div[@class="docblock"]' 'Docs associated with the trait a_method definition.'
7365
pub struct S3(usize);
7466

7567
/// Docs associated with the S3 trait implementation.

src/test/rustdoc/item-hide-threshold.rs renamed to src/test/rustdoc/toggle-item-contents.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#![allow(unused)]
22

3-
// @has 'item_hide_threshold/struct.PubStruct.html'
3+
// @has 'toggle_item_contents/struct.PubStruct.html'
44
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 0
55
pub struct PubStruct {
66
pub a: usize,
77
pub b: usize,
88
}
99

10-
// @has 'item_hide_threshold/struct.BigPubStruct.html'
10+
// @has 'toggle_item_contents/struct.BigPubStruct.html'
1111
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
1212
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show fields'
1313
pub struct BigPubStruct {
@@ -26,7 +26,7 @@ pub struct BigPubStruct {
2626
pub m: usize,
2727
}
2828

29-
// @has 'item_hide_threshold/union.BigUnion.html'
29+
// @has 'toggle_item_contents/union.BigUnion.html'
3030
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
3131
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show fields'
3232
pub union BigUnion {
@@ -45,23 +45,23 @@ pub union BigUnion {
4545
pub m: usize,
4646
}
4747

48-
// @has 'item_hide_threshold/union.Union.html'
48+
// @has 'toggle_item_contents/union.Union.html'
4949
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 0
5050
pub union Union {
5151
pub a: usize,
5252
pub b: usize,
5353
pub c: usize,
5454
}
5555

56-
// @has 'item_hide_threshold/struct.PrivStruct.html'
56+
// @has 'toggle_item_contents/struct.PrivStruct.html'
5757
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 0
5858
// @has - '//div[@class="docblock type-decl"]' 'fields omitted'
5959
pub struct PrivStruct {
6060
a: usize,
6161
b: usize,
6262
}
6363

64-
// @has 'item_hide_threshold/enum.Enum.html'
64+
// @has 'toggle_item_contents/enum.Enum.html'
6565
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
6666
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show fields'
6767
pub enum Enum {
@@ -72,14 +72,14 @@ pub enum Enum {
7272
}
7373
}
7474

75-
// @has 'item_hide_threshold/enum.LargeEnum.html'
75+
// @has 'toggle_item_contents/enum.LargeEnum.html'
7676
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
7777
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show variants'
7878
pub enum LargeEnum {
7979
A, B, C, D, E, F(u8), G, H, I, J, K, L, M
8080
}
8181

82-
// @has 'item_hide_threshold/trait.Trait.html'
82+
// @has 'toggle_item_contents/trait.Trait.html'
8383
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 0
8484
pub trait Trait {
8585
type A;
@@ -88,7 +88,7 @@ pub trait Trait {
8888
fn bar();
8989
}
9090

91-
// @has 'item_hide_threshold/trait.GinormousTrait.html'
91+
// @has 'toggle_item_contents/trait.GinormousTrait.html'
9292
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
9393
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show associated items'
9494
pub trait GinormousTrait {
@@ -111,7 +111,7 @@ pub trait GinormousTrait {
111111
fn bar();
112112
}
113113

114-
// @has 'item_hide_threshold/trait.HugeTrait.html'
114+
// @has 'toggle_item_contents/trait.HugeTrait.html'
115115
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
116116
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show associated constants and methods'
117117
pub trait HugeTrait {
@@ -133,7 +133,7 @@ pub trait HugeTrait {
133133
fn bar();
134134
}
135135

136-
// @has 'item_hide_threshold/trait.BigTrait.html'
136+
// @has 'toggle_item_contents/trait.BigTrait.html'
137137
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
138138
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show methods'
139139
pub trait BigTrait {

src/test/rustdoc/toggle-method.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_name = "foo"]
2+
3+
// Struct methods with documentation should be wrapped in a <details> toggle with an appropriate
4+
// summary. Struct methods with no documentation should not be wrapped.
5+
//
6+
// @has foo/struct.Foo.html
7+
// @has - '//details[@class="rustdoc-toggle method-toggle"]//summary//code' 'is_documented()'
8+
// @has - '//details[@class="rustdoc-toggle method-toggle"]//*[@class="docblock"]' 'is_documented is documented'
9+
// @!has - '//details[@class="rustdoc-toggle method-toggle"]//summary//code' 'not_documented()'
10+
pub struct Foo {
11+
}
12+
13+
impl Foo {
14+
pub fn not_documented() {}
15+
16+
/// is_documented is documented
17+
pub fn is_documented() {}
18+
}

src/test/rustdoc/toggle-trait-fn.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
#![crate_name = "foo"]
22

3+
// Trait methods with documentation should be wrapped in a <details> toggle with an appropriate
4+
// summary. Trait methods with no documentation should not be wrapped.
5+
//
36
// @has foo/trait.Foo.html
4-
// @!has - '//details[@class="rustdoc-toggle"]//code' 'bar'
5-
// @has - '//code' 'bar'
6-
// @has - '//details[@class="rustdoc-toggle"]//code' 'foo'
7+
// @has - '//details[@class="rustdoc-toggle"]//summary//code' 'is_documented()'
8+
// @!has - '//details[@class="rustdoc-toggle"]//summary//code' 'not_documented()'
9+
// @has - '//details[@class="rustdoc-toggle"]//*[@class="docblock"]' 'is_documented is documented'
10+
// @has - '//details[@class="rustdoc-toggle"]//summary//code' 'is_documented_optional()'
11+
// @!has - '//details[@class="rustdoc-toggle"]//summary//code' 'not_documented_optional()'
12+
// @has - '//details[@class="rustdoc-toggle"]//*[@class="docblock"]' 'is_documented_optional is documented'
713
pub trait Foo {
8-
fn bar() -> ();
9-
/// hello
10-
fn foo();
14+
fn not_documented();
15+
16+
/// is_documented is documented
17+
fn is_documented();
18+
19+
fn not_documented_optional() {}
20+
21+
/// is_documented_optional is documented
22+
fn is_documented_optional() {}
1123
}

0 commit comments

Comments
 (0)