lint on variant and fields as well

This commit is contained in:
lucarlig 2024-02-25 22:33:16 +04:00
parent f066be7e1e
commit d84d9d32f1
3 changed files with 127 additions and 81 deletions

View File

@ -399,6 +399,16 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
check_attrs(cx, &self.valid_idents, attrs); check_attrs(cx, &self.valid_idents, attrs);
} }
fn check_variant(&mut self, cx: &LateContext<'tcx>, variant: &'tcx hir::Variant<'tcx>) {
let attrs = cx.tcx.hir().attrs(variant.hir_id);
check_attrs(cx, &self.valid_idents, attrs);
}
fn check_field_def(&mut self, cx: &LateContext<'tcx>, variant: &'tcx hir::FieldDef<'tcx>) {
let attrs = cx.tcx.hir().attrs(variant.hir_id);
check_attrs(cx, &self.valid_idents, attrs);
}
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
let attrs = cx.tcx.hir().attrs(item.hir_id()); let attrs = cx.tcx.hir().attrs(item.hir_id());
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {

View File

@ -1,5 +1,7 @@
#![allow(unused)] #![allow(unused)]
#![warn(clippy::empty_docs)] #![warn(clippy::empty_docs)]
mod outer {
//!
/// this is a struct /// this is a struct
struct Bananas { struct Bananas {
@ -9,22 +11,14 @@ struct Bananas {
/// ///
enum Warn { enum Warn {
///
A,
///
B,
}
enum WarnA {
/// ///
A, A,
B, B,
} }
enum DontWarn { enum DontWarn {
/// it's ok /// i
A, A,
///
B, B,
} }
@ -38,12 +32,10 @@ fn this_doesn_warn() {}
#[doc = "a fine function"] #[doc = "a fine function"]
fn this_is_fine() {} fn this_is_fine() {}
fn warn_about_this_as_well() {
//!
}
/// ///
fn warn_inner_outer() { mod inner {
///
fn dont_warn_inner_outer() {
//!w //!w
} }
@ -60,4 +52,16 @@ fn dont_warn() {
/*! dont warn me */ /*! dont warn me */
} }
trait NoDoc {} trait NoDoc {
///
fn some() {}
}
}
union Unite {
/// lint y
x: i32,
///
y: i32,
}
}

View File

@ -1,7 +1,7 @@
error: empty doc comment error: empty doc comment
--> tests/ui/empty_docs.rs:10:1 --> tests/ui/empty_docs.rs:4:5
| |
LL | /// LL | //!
| ^^^ | ^^^
| |
= help: consider removing or filling it = help: consider removing or filling it
@ -9,7 +9,23 @@ LL | ///
= help: to override `-D warnings` add `#[allow(clippy::empty_docs)]` = help: to override `-D warnings` add `#[allow(clippy::empty_docs)]`
error: empty doc comment error: empty doc comment
--> tests/ui/empty_docs.rs:31:1 --> tests/ui/empty_docs.rs:12:5
|
LL | ///
| ^^^
|
= help: consider removing or filling it
error: empty doc comment
--> tests/ui/empty_docs.rs:14:9
|
LL | ///
| ^^^
|
= help: consider removing or filling it
error: empty doc comment
--> tests/ui/empty_docs.rs:25:5
| |
LL | #[doc = ""] LL | #[doc = ""]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
@ -17,29 +33,45 @@ LL | #[doc = ""]
= help: consider removing or filling it = help: consider removing or filling it
error: empty doc comment error: empty doc comment
--> tests/ui/empty_docs.rs:34:1 --> tests/ui/empty_docs.rs:28:5
| |
LL | / #[doc = ""] LL | / #[doc = ""]
LL | | #[doc = ""] LL | | #[doc = ""]
| |___________^ | |_______________^
| |
= help: consider removing or filling it = help: consider removing or filling it
error: empty doc comment error: empty doc comment
--> tests/ui/empty_docs.rs:42:5 --> tests/ui/empty_docs.rs:35:5
| |
LL | //! LL | ///
| ^^^ | ^^^
| |
= help: consider removing or filling it = help: consider removing or filling it
error: empty doc comment error: empty doc comment
--> tests/ui/empty_docs.rs:56:5 --> tests/ui/empty_docs.rs:48:13
| |
LL | /*! */ LL | /*! */
| ^^^^^^ | ^^^^^^
| |
= help: consider removing or filling it = help: consider removing or filling it
error: aborting due to 5 previous errors error: empty doc comment
--> tests/ui/empty_docs.rs:56:13
|
LL | ///
| ^^^
|
= help: consider removing or filling it
error: empty doc comment
--> tests/ui/empty_docs.rs:64:9
|
LL | ///
| ^^^
|
= help: consider removing or filling it
error: aborting due to 9 previous errors