Skip to content

Commit 7a91d72

Browse files
committed
Add test case for unused doc comments nest
1 parent 86b83a3 commit 7a91d72

2 files changed

Lines changed: 148 additions & 13 deletions

File tree

tests/ui/lint/unused/unused-doc-comments-edge-cases.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unused)]
12
#![deny(unused_doc_comments)]
23

34
fn doc_comment_on_match_arms(num: u8) -> bool {
@@ -69,4 +70,31 @@ extern "C" {
6970
fn foo();
7071
}
7172

72-
fn main() {}
73+
fn main() {
74+
/// Check //~ ERROR: unused doc comment
75+
struct Foo {
76+
/// Check //~ ERROR: unused doc comment
77+
f: i32,
78+
}
79+
80+
/// Check //~ ERROR: unused doc comment
81+
enum Bar {
82+
/// Check //~ ERROR: unused doc comment
83+
F {
84+
/// Check //~ ERROR: unused doc comment
85+
f: i32,
86+
}
87+
}
88+
89+
/// Check //~ ERROR: unused doc comment
90+
union Baz {
91+
/// Check //~ ERROR: unused doc comment
92+
f: i32,
93+
}
94+
95+
/// Check //~ ERROR: unused doc comment
96+
fn fn_1() {
97+
/// Check //~ ERROR: unused doc comment
98+
fn fn_2() {}
99+
}
100+
}

tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr

Lines changed: 119 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: expected expression, found keyword `else`
2-
--> $DIR/unused-doc-comments-edge-cases.rs:17:5
2+
--> $DIR/unused-doc-comments-edge-cases.rs:18:5
33
|
44
LL | else {
55
| ^^^^ expected expression
66

77
error[E0658]: attributes on expressions are experimental
8-
--> $DIR/unused-doc-comments-edge-cases.rs:23:5
8+
--> $DIR/unused-doc-comments-edge-cases.rs:24:5
99
|
1010
LL | /// useless doc comment
1111
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | /// useless doc comment
1616
= help: `///` is used for outer documentation comments; for a plain comment, use `//`
1717

1818
error: unused doc comment
19-
--> $DIR/unused-doc-comments-edge-cases.rs:6:9
19+
--> $DIR/unused-doc-comments-edge-cases.rs:7:9
2020
|
2121
LL | /// useless doc comment
2222
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -26,13 +26,13 @@ LL | _ => false,
2626
|
2727
= help: use `//` for a plain comment
2828
note: the lint level is defined here
29-
--> $DIR/unused-doc-comments-edge-cases.rs:1:9
29+
--> $DIR/unused-doc-comments-edge-cases.rs:2:9
3030
|
3131
LL | #![deny(unused_doc_comments)]
3232
| ^^^^^^^^^^^^^^^^^^^
3333

3434
error: unused doc comment
35-
--> $DIR/unused-doc-comments-edge-cases.rs:23:5
35+
--> $DIR/unused-doc-comments-edge-cases.rs:24:5
3636
|
3737
LL | /// useless doc comment
3838
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -43,7 +43,7 @@ LL | num == 3
4343
= help: use `//` for a plain comment
4444

4545
error: unused doc comment
46-
--> $DIR/unused-doc-comments-edge-cases.rs:33:9
46+
--> $DIR/unused-doc-comments-edge-cases.rs:34:9
4747
|
4848
LL | /// useless doc comment
4949
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -54,7 +54,7 @@ LL | foo: 3
5454
= help: use `//` for a plain comment
5555

5656
error: unused doc comment
57-
--> $DIR/unused-doc-comments-edge-cases.rs:45:9
57+
--> $DIR/unused-doc-comments-edge-cases.rs:46:9
5858
|
5959
LL | /// useless doc comment
6060
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -65,15 +65,15 @@ LL | foo
6565
= help: use `//` for a plain comment
6666

6767
error: unused doc comment
68-
--> $DIR/unused-doc-comments-edge-cases.rs:55:27
68+
--> $DIR/unused-doc-comments-edge-cases.rs:56:27
6969
|
7070
LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {}
7171
| ^^^^^^^^^^^^ - rustdoc does not generate documentation for generic parameters
7272
|
7373
= help: use `//` for a plain comment
7474

7575
error: unused doc comment
76-
--> $DIR/unused-doc-comments-edge-cases.rs:59:5
76+
--> $DIR/unused-doc-comments-edge-cases.rs:60:5
7777
|
7878
LL | /// unused doc comment
7979
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -86,7 +86,7 @@ LL | | }
8686
= help: use `//` for a plain comment
8787

8888
error: unused doc comment
89-
--> $DIR/unused-doc-comments-edge-cases.rs:66:1
89+
--> $DIR/unused-doc-comments-edge-cases.rs:67:1
9090
|
9191
LL | /// unused doc comment
9292
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -98,8 +98,115 @@ LL | | }
9898
|
9999
= help: use `//` for a plain comment
100100

101+
error: unused doc comment
102+
--> $DIR/unused-doc-comments-edge-cases.rs:74:5
103+
|
104+
LL | /// Check
105+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106+
LL | / struct Foo {
107+
LL | | /// Check
108+
LL | | f: i32,
109+
LL | | }
110+
| |_____- rustdoc does not generate documentation for items defined in functions
111+
|
112+
= help: use `//` for a plain comment
113+
114+
error: unused doc comment
115+
--> $DIR/unused-doc-comments-edge-cases.rs:76:9
116+
|
117+
LL | /// Check
118+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119+
LL | f: i32,
120+
| ------ rustdoc does not generate documentation for fields defined nested in functions
121+
|
122+
= help: use `//` for a plain comment
123+
124+
error: unused doc comment
125+
--> $DIR/unused-doc-comments-edge-cases.rs:80:5
126+
|
127+
LL | /// Check
128+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
129+
LL | / enum Bar {
130+
LL | | /// Check
131+
LL | | F {
132+
LL | | /// Check
133+
... |
134+
LL | | }
135+
| |_____- rustdoc does not generate documentation for items defined in functions
136+
|
137+
= help: use `//` for a plain comment
138+
139+
error: unused doc comment
140+
--> $DIR/unused-doc-comments-edge-cases.rs:82:9
141+
|
142+
LL | /// Check
143+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144+
LL | / F {
145+
LL | | /// Check
146+
LL | | f: i32,
147+
LL | | }
148+
| |_________- rustdoc does not generate documentation for variants defined nested in functions
149+
|
150+
= help: use `//` for a plain comment
151+
152+
error: unused doc comment
153+
--> $DIR/unused-doc-comments-edge-cases.rs:84:13
154+
|
155+
LL | /// Check
156+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
157+
LL | f: i32,
158+
| ------ rustdoc does not generate documentation for fields defined nested in functions
159+
|
160+
= help: use `//` for a plain comment
161+
162+
error: unused doc comment
163+
--> $DIR/unused-doc-comments-edge-cases.rs:89:5
164+
|
165+
LL | /// Check
166+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167+
LL | / union Baz {
168+
LL | | /// Check
169+
LL | | f: i32,
170+
LL | | }
171+
| |_____- rustdoc does not generate documentation for items defined in functions
172+
|
173+
= help: use `//` for a plain comment
174+
175+
error: unused doc comment
176+
--> $DIR/unused-doc-comments-edge-cases.rs:91:9
177+
|
178+
LL | /// Check
179+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
180+
LL | f: i32,
181+
| ------ rustdoc does not generate documentation for fields defined nested in functions
182+
|
183+
= help: use `//` for a plain comment
184+
185+
error: unused doc comment
186+
--> $DIR/unused-doc-comments-edge-cases.rs:95:5
187+
|
188+
LL | /// Check
189+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
190+
LL | / fn fn_1() {
191+
LL | | /// Check
192+
LL | | fn fn_2() {}
193+
LL | | }
194+
| |_____- rustdoc does not generate documentation for items defined in functions
195+
|
196+
= help: use `//` for a plain comment
197+
198+
error: unused doc comment
199+
--> $DIR/unused-doc-comments-edge-cases.rs:97:9
200+
|
201+
LL | /// Check
202+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
203+
LL | fn fn_2() {}
204+
| ------------ rustdoc does not generate documentation for items defined in functions
205+
|
206+
= help: use `//` for a plain comment
207+
101208
error[E0308]: mismatched types
102-
--> $DIR/unused-doc-comments-edge-cases.rs:14:9
209+
--> $DIR/unused-doc-comments-edge-cases.rs:15:9
103210
|
104211
LL | / if num == 3 {
105212
LL | | true
@@ -112,7 +219,7 @@ help: you might have meant to return this value
112219
LL | return true;
113220
| ++++++ +
114221

115-
error: aborting due to 10 previous errors
222+
error: aborting due to 19 previous errors
116223

117224
Some errors have detailed explanations: E0308, E0658.
118225
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)