Skip to content

Commit d95ca28

Browse files
committed
Add tests against weird provided/required method behaviour
In `test/rustdoc/manual_impl.rs` there are now three structs: * S1 implements and documents required method `a_method`. * S2 implements and documents `a_method` as well as provided method `b_method`. * S3 implements `a_method` and `b_method`, but only documents `b_method`. For a struct, we want the rendered trait impls to include documentation if and only if it appears on the trait implementation itself (since users can just go to the trait definition for anything not covered in the impl docs). This means we expect: * S1, S2, and S3 to all include top-level trait impl docs. * S1, S2, and S3 to exclude all trait definition docs. * S1 to show impl docs for `a_method`. * S2 to show impl docs for `a_method` and `b_method`. * S3 to show impl docs for `b_method`. These tests cover those cases.
1 parent d8d8669 commit d95ca28

File tree

1 file changed

+55
-7
lines changed

1 file changed

+55
-7
lines changed

src/test/rustdoc/manual_impl.rs

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,67 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
/// Docs associated with the trait definition.
1112
pub trait T {
13+
/// Docs associated with the trait a_method definition.
1214
fn a_method(&self) -> usize;
15+
16+
/// Docs associated with the trait b_method definition.
17+
fn b_method(&self) -> usize {
18+
self.a_method()
19+
}
20+
}
21+
22+
// @has manual_impl/struct.S1.html '//*[@class="trait"]' 'T'
23+
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait implementation.'
24+
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait a_method implementation.'
25+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
26+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
27+
pub struct S1(usize);
28+
29+
/// Docs associated with the S1 trait implementation.
30+
impl T for S1 {
31+
/// Docs associated with the S1 trait a_method implementation.
32+
fn a_method(&self) -> usize {
33+
self.0
34+
}
35+
}
36+
37+
// @has manual_impl/struct.S2.html '//*[@class="trait"]' 'T'
38+
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait implementation.'
39+
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait a_method implementation.'
40+
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait b_method implementation.'
41+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
42+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
43+
pub struct S2(usize);
44+
45+
/// Docs associated with the S2 trait implementation.
46+
impl T for S2 {
47+
/// Docs associated with the S2 trait a_method implementation.
48+
fn a_method(&self) -> usize {
49+
self.0
50+
}
51+
52+
/// Docs associated with the S2 trait b_method implementation.
53+
fn b_method(&self) -> usize {
54+
5
55+
}
1356
}
1457

15-
// @has manual_impl/struct.S.html '//*[@class="trait"]' 'T'
16-
// @has - '//*[@class="docblock"]' 'Docs associated with the trait implementation.'
17-
// @has - '//*[@class="docblock"]' 'Docs associated with the trait method implementation.'
18-
pub struct S(usize);
58+
// @has manual_impl/struct.S3.html '//*[@class="trait"]' 'T'
59+
// @has - '//*[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
60+
// @has - '//*[@class="docblock"]' 'Docs associated with the S3 trait b_method implementation.'
61+
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
62+
pub struct S3(usize);
1963

20-
/// Docs associated with the trait implementation.
21-
impl T for S {
22-
/// Docs associated with the trait method implementation.
64+
/// Docs associated with the S3 trait implementation.
65+
impl T for S3 {
2366
fn a_method(&self) -> usize {
2467
self.0
2568
}
69+
70+
/// Docs associated with the S3 trait b_method implementation.
71+
fn b_method(&self) -> usize {
72+
5
73+
}
2674
}

0 commit comments

Comments
 (0)