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,63 +1,67 @@
#![allow(unused)] #![allow(unused)]
#![warn(clippy::empty_docs)] #![warn(clippy::empty_docs)]
mod outer {
/// this is a struct
struct Bananas {
/// count
count: usize,
}
///
enum Warn {
///
A,
///
B,
}
enum WarnA {
///
A,
B,
}
enum DontWarn {
/// it's ok
A,
///
B,
}
#[doc = ""]
fn warn_about_this() {}
#[doc = ""]
#[doc = ""]
fn this_doesn_warn() {}
#[doc = "a fine function"]
fn this_is_fine() {}
fn warn_about_this_as_well() {
//! //!
}
/// /// this is a struct
fn warn_inner_outer() { struct Bananas {
//!w /// count
} count: usize,
}
fn this_is_ok() { ///
//! enum Warn {
//! inside the function ///
} A,
B,
}
fn warn() { enum DontWarn {
/*! */ /// i
} A,
B,
}
fn dont_warn() { #[doc = ""]
/*! dont warn me */ fn warn_about_this() {}
}
trait NoDoc {} #[doc = ""]
#[doc = ""]
fn this_doesn_warn() {}
#[doc = "a fine function"]
fn this_is_fine() {}
///
mod inner {
///
fn dont_warn_inner_outer() {
//!w
}
fn this_is_ok() {
//!
//! inside the function
}
fn warn() {
/*! */
}
fn dont_warn() {
/*! dont warn me */
}
trait NoDoc {
///
fn some() {}
}
}
union Unite {
/// lint y
x: i32,
///
y: i32,
}
}

View File

@ -1,45 +1,77 @@
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
= note: `-D clippy::empty-docs` implied by `-D warnings` = note: `-D clippy::empty-docs` implied by `-D warnings`
= 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 | #[doc = ""] LL | ///
| ^^^^^^^^^^^
|
= help: consider removing or filling it
error: empty doc comment
--> tests/ui/empty_docs.rs:34:1
|
LL | / #[doc = ""]
LL | | #[doc = ""]
| |___________^
|
= help: consider removing or filling it
error: empty doc comment
--> tests/ui/empty_docs.rs:42:5
|
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:14:9
| |
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:25:5
|
LL | #[doc = ""]
| ^^^^^^^^^^^
|
= help: consider removing or filling it
error: empty doc comment
--> tests/ui/empty_docs.rs:28:5
|
LL | / #[doc = ""]
LL | | #[doc = ""]
| |_______________^
|
= help: consider removing or filling it
error: empty doc comment
--> tests/ui/empty_docs.rs:35:5
|
LL | ///
| ^^^
|
= help: consider removing or filling it
error: empty doc comment
--> tests/ui/empty_docs.rs:48:13
|
LL | /*! */
| ^^^^^^
|
= help: consider removing or filling it
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