Skip to content

Commit 95b6d00

Browse files
committed
add test 3, fmt and lint
1 parent e3876fb commit 95b6d00

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

clippy_lints/src/missing_doc.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
263263
}
264264

265265
fn check_field_def(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::FieldDef<'_>) {
266-
if !sf.is_positional() {
267-
// Skip checking if the field starts with an underscore and allow_unused is enabled
268-
if self.allow_unused && sf.ident.as_str().starts_with('_') {
269-
self.prev_span = Some(sf.span);
270-
return;
271-
}
272-
266+
if !(sf.is_positional()
267+
|| is_from_proc_macro(cx, sf)
268+
|| self.allow_unused && sf.ident.as_str().starts_with('_'))
269+
{
273270
let attrs = cx.tcx.hir_attrs(sf.hir_id);
274-
if !is_from_proc_macro(cx, sf) {
275-
self.check_missing_docs_attrs(cx, sf.def_id, attrs, sf.span, "a", "struct field");
276-
}
271+
self.check_missing_docs_attrs(cx, sf.def_id, attrs, sf.span, "a", "struct field");
277272
}
278273
self.prev_span = Some(sf.span);
279274
}

tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ struct Test2 {
1616
_field2: i32, // This should not trigger a warning
1717
}
1818

19+
struct Test3 {
20+
//~^ missing_docs_in_private_items
21+
/// This field is documented although this is not mandatory
22+
_unused: i32, // This should not trigger a warning because it starts with an underscore
23+
field2: i32, //~ missing_docs_in_private_items
24+
}
25+
1926
fn main() {}

tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.stderr

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,22 @@ LL | | _field2: i32, // This should not trigger a warning
1717
LL | | }
1818
| |_^
1919

20-
error: aborting due to 2 previous errors
20+
error: missing documentation for a struct
21+
--> tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs:19:1
22+
|
23+
LL | / struct Test3 {
24+
LL | |
25+
LL | | /// This field is documented although this is not mandatory
26+
LL | | _unused: i32, // This should not trigger a warning because it starts with an underscore
27+
LL | | field2: i32,
28+
LL | | }
29+
| |_^
30+
31+
error: missing documentation for a struct field
32+
--> tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs:23:5
33+
|
34+
LL | field2: i32,
35+
| ^^^^^^^^^^^
36+
37+
error: aborting due to 4 previous errors
2138

0 commit comments

Comments
 (0)