diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 5690bd1d1ba..76fd900bff3 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -399,6 +399,16 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { 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<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { diff --git a/tests/ui/empty_docs.rs b/tests/ui/empty_docs.rs index f5b4bb6736d..c47a603e71b 100644 --- a/tests/ui/empty_docs.rs +++ b/tests/ui/empty_docs.rs @@ -1,63 +1,67 @@ #![allow(unused)] #![warn(clippy::empty_docs)] - -/// 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() { +mod outer { //! -} -/// -fn warn_inner_outer() { - //!w -} + /// this is a struct + struct Bananas { + /// count + count: usize, + } -fn this_is_ok() { - //! - //! inside the function -} + /// + enum Warn { + /// + A, + B, + } -fn warn() { - /*! */ -} + enum DontWarn { + /// i + A, + B, + } -fn dont_warn() { - /*! dont warn me */ -} + #[doc = ""] + 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, + } +} diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr index a2d8b986bf0..3f1d071fb13 100644 --- a/tests/ui/empty_docs.stderr +++ b/tests/ui/empty_docs.stderr @@ -1,45 +1,77 @@ 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 = note: `-D clippy::empty-docs` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_docs)]` error: empty doc comment - --> tests/ui/empty_docs.rs:31:1 + --> tests/ui/empty_docs.rs:12:5 | -LL | #[doc = ""] - | ^^^^^^^^^^^ - | - = 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 | //! +LL | /// | ^^^ | = help: consider removing or filling it 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 -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