From 3093b291f6ba37dd51d45d002e6863b44ee3af7d Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 09:55:58 +0400 Subject: [PATCH 01/17] WIP: empty doc span is still broken --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/doc/mod.rs | 65 ++++++++++++++++++++++++++++-- tests/ui/empty_docs.rs | 43 ++++++++++++++++++++ tests/ui/empty_docs.stderr | 35 ++++++++++++++++ 5 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 tests/ui/empty_docs.rs create mode 100644 tests/ui/empty_docs.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 5805511c70f9..eef43ed88822 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5158,6 +5158,7 @@ Released 2018-09-13 [`duration_subsec`]: https://rust-lang.github.io/rust-clippy/master/index.html#duration_subsec [`eager_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#eager_transmute [`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else +[`empty_docs`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_docs [`empty_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_drop [`empty_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum [`empty_enum_variants_with_brackets`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum_variants_with_brackets diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 79fd76393074..eef66c4a51b7 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -139,6 +139,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::disallowed_types::DISALLOWED_TYPES_INFO, crate::doc::DOC_LINK_WITH_QUOTES_INFO, crate::doc::DOC_MARKDOWN_INFO, + crate::doc::EMPTY_DOCS_INFO, crate::doc::MISSING_ERRORS_DOC_INFO, crate::doc::MISSING_PANICS_DOC_INFO, crate::doc::MISSING_SAFETY_DOC_INFO, diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 2b4ce6ddfaaa..26bfdf4a072c 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -23,7 +23,7 @@ use rustc_resolve::rustdoc::{ }; use rustc_session::impl_lint_pass; use rustc_span::edition::Edition; -use rustc_span::{sym, Span}; +use rustc_span::{sym, Span, DUMMY_SP}; use std::ops::Range; use url::Url; @@ -338,6 +338,29 @@ declare_clippy_lint! { "suspicious usage of (outer) doc comments" } +declare_clippy_lint! { + /// ### What it does + /// Detects documentation that is empty. + /// ### Why is this bad? + /// It is unlikely that there is any reason to have empty documentation for an item + /// ### Example + /// ```rust + /// /// + /// fn returns_true() -> bool { + /// true + /// } + /// Use instead: + /// ```rust + /// fn returns_true() -> bool { + /// true + /// } + /// ``` + #[clippy::version = "1.78.0"] + pub EMPTY_DOCS, + suspicious, + "docstrings exist but documentation is empty" +} + #[derive(Clone)] pub struct Documentation { valid_idents: FxHashSet, @@ -364,7 +387,8 @@ impl_lint_pass!(Documentation => [ NEEDLESS_DOCTEST_MAIN, TEST_ATTR_IN_DOCTEST, UNNECESSARY_SAFETY_DOC, - SUSPICIOUS_DOC_COMMENTS + SUSPICIOUS_DOC_COMMENTS, + EMPTY_DOCS, ]); impl<'tcx> LateLintPass<'tcx> for Documentation { @@ -378,6 +402,20 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { return; }; + + if let Some(span) = get_empty_doc_combined_span(attrs, item.span) + && headers.empty + { + span_lint_and_help( + cx, + EMPTY_DOCS, + span, + "empty doc comment", + None, + "consider removing or filling it", + ); + } + match item.kind { hir::ItemKind::Fn(ref sig, _, body_id) => { if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) { @@ -477,6 +515,7 @@ struct DocHeaders { safety: bool, errors: bool, panics: bool, + empty: bool, } /// Does some pre-processing on raw, desugared `#[doc]` attributes such as parsing them and @@ -509,7 +548,10 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ doc.pop(); if doc.is_empty() { - return Some(DocHeaders::default()); + return Some(DocHeaders { + empty: true, + ..DocHeaders::default() + }); } let mut cb = fake_broken_link_callback; @@ -717,3 +759,20 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { self.cx.tcx.hir() } } + +fn get_empty_doc_combined_span(attrs: &[Attribute], item_span: Span) -> Option { + let mut attrs_span = DUMMY_SP; + if attrs.len() > 0 { + attrs_span = attrs + .iter() + .map(|attr| attr.span) + .fold(attrs[0].span, |acc, next| acc.to(next)); + } + + match (!item_span.is_dummy(), !attrs_span.is_dummy()) { + (true, true) => Some(item_span.shrink_to_lo().to(attrs_span)), + (true, false) => Some(item_span), + (false, true) => Some(attrs_span), + (false, false) => None, + } +} diff --git a/tests/ui/empty_docs.rs b/tests/ui/empty_docs.rs new file mode 100644 index 000000000000..394e62ab2a61 --- /dev/null +++ b/tests/ui/empty_docs.rs @@ -0,0 +1,43 @@ +#![allow(unused)] +#![warn(clippy::empty_docs)] + +/// this is a struct +struct Bananas { + /// count + count: usize, +} + +/// +enum Warn { + /// + A, + /// + B, +} + +enum WarnForB { + /// it's ok + A, + /// + B, +} + +#[doc = ""] +#[doc = ""] +fn warn_about_this() {} + +#[doc = "a fine function"] +fn this_is_fine() {} + +fn warn_about_this_as_well() { + //! +} + +fn this_is_ok() { + //! + //! inside the function +} + +fn warn() { + /*! inside the function */ +} diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr new file mode 100644 index 000000000000..27d49b4ff3b6 --- /dev/null +++ b/tests/ui/empty_docs.stderr @@ -0,0 +1,35 @@ +error: empty doc comment + --> tests/ui/empty_docs.rs:10:1 + | +LL | / /// +LL | | enum Warn { + | |_ + | + = 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:18:1 + | +LL | / enum WarnForB { +LL | | /// it's ok +LL | | A, +LL | | /// +LL | | B, +LL | | } + | |_^ + | + = help: consider removing or filling it + +error: empty doc comment + --> tests/ui/empty_docs.rs:32:1 + | +LL | / fn warn_about_this_as_well() { +LL | | //! + | |_______^ + | + = help: consider removing or filling it + +error: aborting due to 3 previous errors + From 84219f45a3fd2a5bb86dd5ba6c56408193f16af3 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 16:11:14 +0400 Subject: [PATCH 02/17] working naive with outside check_attrs --- clippy_lints/src/doc/empty_docs.rs | 25 ++++++++++++++++++++++ clippy_lints/src/doc/mod.rs | 33 ++++-------------------------- tests/ui/empty_docs.rs | 24 +++++++++++++++++++--- tests/ui/empty_docs.stderr | 23 ++++++++------------- 4 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 clippy_lints/src/doc/empty_docs.rs diff --git a/clippy_lints/src/doc/empty_docs.rs b/clippy_lints/src/doc/empty_docs.rs new file mode 100644 index 000000000000..bd5aeba922b5 --- /dev/null +++ b/clippy_lints/src/doc/empty_docs.rs @@ -0,0 +1,25 @@ +use clippy_utils::diagnostics::span_lint_and_help; +use rustc_ast::Attribute; +use rustc_lint::LateContext; + +use super::EMPTY_DOCS; + +// TODO: Adjust the parameters as necessary +pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) { + let doc_attrs: Vec<_> = attrs.iter().filter(|attr| attr.doc_str().is_some()).collect(); + + let span; + if let Some(first) = doc_attrs.first() + && let Some(last) = doc_attrs.last() + { + span = first.span.with_hi(last.span.hi()); + span_lint_and_help( + cx, + EMPTY_DOCS, + span, + "empty doc comment", + None, + "consider removing or filling it", + ); + } +} diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 26bfdf4a072c..a0e23983d1da 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -23,10 +23,11 @@ use rustc_resolve::rustdoc::{ }; use rustc_session::impl_lint_pass; use rustc_span::edition::Edition; -use rustc_span::{sym, Span, DUMMY_SP}; +use rustc_span::{sym, Span}; use std::ops::Range; use url::Url; +mod empty_docs; mod link_with_quotes; mod markdown; mod missing_headers; @@ -403,17 +404,8 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { return; }; - if let Some(span) = get_empty_doc_combined_span(attrs, item.span) - && headers.empty - { - span_lint_and_help( - cx, - EMPTY_DOCS, - span, - "empty doc comment", - None, - "consider removing or filling it", - ); + if headers.empty && !item.span.is_dummy() { + empty_docs::check(cx, attrs); } match item.kind { @@ -759,20 +751,3 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { self.cx.tcx.hir() } } - -fn get_empty_doc_combined_span(attrs: &[Attribute], item_span: Span) -> Option { - let mut attrs_span = DUMMY_SP; - if attrs.len() > 0 { - attrs_span = attrs - .iter() - .map(|attr| attr.span) - .fold(attrs[0].span, |acc, next| acc.to(next)); - } - - match (!item_span.is_dummy(), !attrs_span.is_dummy()) { - (true, true) => Some(item_span.shrink_to_lo().to(attrs_span)), - (true, false) => Some(item_span), - (false, true) => Some(attrs_span), - (false, false) => None, - } -} diff --git a/tests/ui/empty_docs.rs b/tests/ui/empty_docs.rs index 394e62ab2a61..30b1f0ed2e2c 100644 --- a/tests/ui/empty_docs.rs +++ b/tests/ui/empty_docs.rs @@ -15,17 +15,26 @@ enum Warn { B, } -enum WarnForB { +enum WarnA { + /// + A, + B, +} + +enum DontWarn { /// it's ok A, /// B, } -#[doc = ""] #[doc = ""] fn warn_about_this() {} +#[doc = ""] +#[doc = ""] +fn this_doesn_warn() {} + #[doc = "a fine function"] fn this_is_fine() {} @@ -33,11 +42,20 @@ fn warn_about_this_as_well() { //! } +/// +fn warn_inner_outer() { + //! what +} + fn this_is_ok() { //! //! inside the function } fn warn() { - /*! inside the function */ + /*! */ +} + +fn dont_warn() { + /*! dont warn me */ } diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr index 27d49b4ff3b6..0c2f17557763 100644 --- a/tests/ui/empty_docs.stderr +++ b/tests/ui/empty_docs.stderr @@ -1,33 +1,26 @@ error: empty doc comment --> tests/ui/empty_docs.rs:10:1 | -LL | / /// -LL | | enum Warn { - | |_ +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:18:1 + --> tests/ui/empty_docs.rs:31:1 | -LL | / enum WarnForB { -LL | | /// it's ok -LL | | A, -LL | | /// -LL | | B, -LL | | } - | |_^ +LL | #[doc = ""] + | ^^^^^^^^^^^ | = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:32:1 + --> tests/ui/empty_docs.rs:42:5 | -LL | / fn warn_about_this_as_well() { -LL | | //! - | |_______^ +LL | //! + | ^^^ | = help: consider removing or filling it From 09c7c5d2c9f23c16b39d2fade5567010fe33471d Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 16:52:58 +0400 Subject: [PATCH 03/17] fix bug in check_exprs --- clippy_lints/src/doc/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index a0e23983d1da..be6748bdb7d3 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -533,10 +533,14 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ suspicious_doc_comments::check(cx, attrs); let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true); - let mut doc = String::new(); - for fragment in &fragments { - add_doc_fragment(&mut doc, fragment); - } + let mut doc = fragments + .iter() + .fold(String::new(), |mut acc, fragment| { + add_doc_fragment(&mut acc, fragment); + acc + }) + .trim() + .to_string(); doc.pop(); if doc.is_empty() { From a3fea80a6826154a23eafe8e62f6b18cfae1dfbc Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 17:04:58 +0400 Subject: [PATCH 04/17] bless tests --- tests/ui/empty_docs.stderr | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr index 0c2f17557763..a2d8b986bf06 100644 --- a/tests/ui/empty_docs.stderr +++ b/tests/ui/empty_docs.stderr @@ -16,6 +16,15 @@ 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 | @@ -24,5 +33,13 @@ LL | //! | = help: consider removing or filling it -error: aborting due to 3 previous errors +error: empty doc comment + --> tests/ui/empty_docs.rs:56:5 + | +LL | /*! */ + | ^^^^^^ + | + = help: consider removing or filling it + +error: aborting due to 5 previous errors From 9ac6125e1d034bdc84e9a8508fd96fa55cdf8209 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 17:16:07 +0400 Subject: [PATCH 05/17] add extra variant because no more than 3 bools --- clippy_lints/src/doc/mod.rs | 53 +++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index be6748bdb7d3..78d46928f35e 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -400,11 +400,15 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { 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 { + let Some(DocInfo { + empty, + doc_headers: headers, + }) = check_attrs(cx, &self.valid_idents, attrs) + else { return; }; - if headers.empty && !item.span.is_dummy() { + if empty && !item.span.is_dummy() { empty_docs::check(cx, attrs); } @@ -455,7 +459,11 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); - let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { + let Some(DocInfo { + empty: _, + doc_headers: headers, + }) = check_attrs(cx, &self.valid_idents, attrs) + else { return; }; if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { @@ -467,7 +475,11 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); - let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { + let Some(DocInfo { + empty: _, + doc_headers: headers, + }) = check_attrs(cx, &self.valid_idents, attrs) + else { return; }; if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) { @@ -507,7 +519,12 @@ struct DocHeaders { safety: bool, errors: bool, panics: bool, +} + +#[derive(Copy, Clone, Default)] +struct DocInfo { empty: bool, + doc_headers: DocHeaders, } /// Does some pre-processing on raw, desugared `#[doc]` attributes such as parsing them and @@ -517,7 +534,7 @@ struct DocHeaders { /// Others are checked elsewhere, e.g. in `check_doc` if they need access to markdown, or /// back in the various late lint pass methods if they need the final doc headers, like "Safety" or /// "Panics" sections. -fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[Attribute]) -> Option { +fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[Attribute]) -> Option { /// We don't want the parser to choke on intra doc links. Since we don't /// actually care about rendering them, just pretend that all broken links /// point to a fake address. @@ -542,11 +559,10 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ .trim() .to_string(); doc.pop(); - if doc.is_empty() { - return Some(DocHeaders { + return Some(DocInfo { empty: true, - ..DocHeaders::default() + doc_headers: DocHeaders::default(), }); } @@ -556,15 +572,18 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION; let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb)); - Some(check_doc( - cx, - valid_idents, - parser.into_offset_iter(), - Fragments { - fragments: &fragments, - doc: &doc, - }, - )) + Some(DocInfo { + empty: false, + doc_headers: check_doc( + cx, + valid_idents, + parser.into_offset_iter(), + Fragments { + fragments: &fragments, + doc: &doc, + }, + ), + }) } const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail"]; From 0ea449597e0d0c06dbfa5eccb2c7a785b7cec77e Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 17:23:15 +0400 Subject: [PATCH 06/17] pop before trimming --- clippy_lints/src/doc/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 78d46928f35e..7b085a36ea5e 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -550,15 +550,13 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ suspicious_doc_comments::check(cx, attrs); let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true); - let mut doc = fragments - .iter() - .fold(String::new(), |mut acc, fragment| { - add_doc_fragment(&mut acc, fragment); - acc - }) - .trim() - .to_string(); + let mut doc = fragments.iter().fold(String::new(), |mut acc, fragment| { + add_doc_fragment(&mut acc, fragment); + acc + }); doc.pop(); + let doc = doc.trim().to_string(); + if doc.is_empty() { return Some(DocInfo { empty: true, From ee0cbeaa77dd2c1c25d2da3df35df837efc6cd66 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 17:41:41 +0400 Subject: [PATCH 07/17] ignore empty comment in semicolon_if_nothing_returned --- tests/ui/semicolon_if_nothing_returned.fixed | 7 ++++++- tests/ui/semicolon_if_nothing_returned.rs | 7 ++++++- tests/ui/semicolon_if_nothing_returned.stderr | 10 +++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/ui/semicolon_if_nothing_returned.fixed b/tests/ui/semicolon_if_nothing_returned.fixed index cdfa5d9cc780..6c8c835d0e0e 100644 --- a/tests/ui/semicolon_if_nothing_returned.fixed +++ b/tests/ui/semicolon_if_nothing_returned.fixed @@ -1,7 +1,12 @@ //@aux-build:proc_macro_attr.rs #![warn(clippy::semicolon_if_nothing_returned)] -#![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)] +#![allow( + clippy::redundant_closure, + clippy::uninlined_format_args, + clippy::needless_late_init, + clippy::empty_docs +)] #[macro_use] extern crate proc_macro_attr; diff --git a/tests/ui/semicolon_if_nothing_returned.rs b/tests/ui/semicolon_if_nothing_returned.rs index 315b7e4f3839..2c2e4c024190 100644 --- a/tests/ui/semicolon_if_nothing_returned.rs +++ b/tests/ui/semicolon_if_nothing_returned.rs @@ -1,7 +1,12 @@ //@aux-build:proc_macro_attr.rs #![warn(clippy::semicolon_if_nothing_returned)] -#![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)] +#![allow( + clippy::redundant_closure, + clippy::uninlined_format_args, + clippy::needless_late_init, + clippy::empty_docs +)] #[macro_use] extern crate proc_macro_attr; diff --git a/tests/ui/semicolon_if_nothing_returned.stderr b/tests/ui/semicolon_if_nothing_returned.stderr index 286cf512ed0b..69e434b142cf 100644 --- a/tests/ui/semicolon_if_nothing_returned.stderr +++ b/tests/ui/semicolon_if_nothing_returned.stderr @@ -1,5 +1,5 @@ error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:13:5 + --> tests/ui/semicolon_if_nothing_returned.rs:18:5 | LL | println!("Hello") | ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");` @@ -8,25 +8,25 @@ LL | println!("Hello") = help: to override `-D warnings` add `#[allow(clippy::semicolon_if_nothing_returned)]` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:17:5 + --> tests/ui/semicolon_if_nothing_returned.rs:22:5 | LL | get_unit() | ^^^^^^^^^^ help: add a `;` here: `get_unit();` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:22:5 + --> tests/ui/semicolon_if_nothing_returned.rs:27:5 | LL | y = x + 1 | ^^^^^^^^^ help: add a `;` here: `y = x + 1;` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:28:9 + --> tests/ui/semicolon_if_nothing_returned.rs:33:9 | LL | hello() | ^^^^^^^ help: add a `;` here: `hello();` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:39:9 + --> tests/ui/semicolon_if_nothing_returned.rs:44:9 | LL | ptr::drop_in_place(s.as_mut_ptr()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());` From 97e4c57f24d82d2bd938496b4a1af10372714ef7 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 17:51:58 +0400 Subject: [PATCH 08/17] fix lint doc --- clippy_lints/src/doc/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 7b085a36ea5e..2984c5c15199 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -345,13 +345,14 @@ declare_clippy_lint! { /// ### Why is this bad? /// It is unlikely that there is any reason to have empty documentation for an item /// ### Example - /// ```rust + /// ```rs /// /// /// fn returns_true() -> bool { /// true /// } + /// ``` /// Use instead: - /// ```rust + /// ```rs /// fn returns_true() -> bool { /// true /// } From 5a50cede295bc27768a970ec1a30f3bf8e95df74 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 18:01:53 +0400 Subject: [PATCH 09/17] add single letter test --- tests/ui/empty_docs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/empty_docs.rs b/tests/ui/empty_docs.rs index 30b1f0ed2e2c..77564c1c33df 100644 --- a/tests/ui/empty_docs.rs +++ b/tests/ui/empty_docs.rs @@ -44,7 +44,7 @@ fn warn_about_this_as_well() { /// fn warn_inner_outer() { - //! what + //!w } fn this_is_ok() { From f32e92cdc9a1a33bf82fe4c4b77ec52169b45701 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 21:18:38 +0400 Subject: [PATCH 10/17] add 1 more test and dont trim other code --- clippy_lints/src/doc/mod.rs | 5 ++--- tests/ui/empty_docs.rs | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 2984c5c15199..8b6256a50f4f 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -17,7 +17,7 @@ use rustc_hir::{AnonConst, Expr}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty; +use rustc_middle::ty::{self}; use rustc_resolve::rustdoc::{ add_doc_fragment, attrs_to_doc_fragments, main_body_opts, source_span_for_markdown_range, DocFragment, }; @@ -556,9 +556,8 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ acc }); doc.pop(); - let doc = doc.trim().to_string(); - if doc.is_empty() { + if doc.trim().is_empty() { return Some(DocInfo { empty: true, doc_headers: DocHeaders::default(), diff --git a/tests/ui/empty_docs.rs b/tests/ui/empty_docs.rs index 77564c1c33df..f5b4bb6736d1 100644 --- a/tests/ui/empty_docs.rs +++ b/tests/ui/empty_docs.rs @@ -59,3 +59,5 @@ fn warn() { fn dont_warn() { /*! dont warn me */ } + +trait NoDoc {} From d7ad85f521d94bed54ca74e9f14f327904fa6fe2 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 21:26:43 +0400 Subject: [PATCH 11/17] move the the check into check_atr function --- clippy_lints/src/doc/empty_docs.rs | 1 - clippy_lints/src/doc/mod.rs | 57 ++++++++---------------------- 2 files changed, 15 insertions(+), 43 deletions(-) diff --git a/clippy_lints/src/doc/empty_docs.rs b/clippy_lints/src/doc/empty_docs.rs index bd5aeba922b5..b0be71139616 100644 --- a/clippy_lints/src/doc/empty_docs.rs +++ b/clippy_lints/src/doc/empty_docs.rs @@ -7,7 +7,6 @@ use super::EMPTY_DOCS; // TODO: Adjust the parameters as necessary pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) { let doc_attrs: Vec<_> = attrs.iter().filter(|attr| attr.doc_str().is_some()).collect(); - let span; if let Some(first) = doc_attrs.first() && let Some(last) = doc_attrs.last() diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 8b6256a50f4f..5690bd1d1ba3 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -401,18 +401,10 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); - let Some(DocInfo { - empty, - doc_headers: headers, - }) = check_attrs(cx, &self.valid_idents, attrs) - else { + let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { return; }; - if empty && !item.span.is_dummy() { - empty_docs::check(cx, attrs); - } - match item.kind { hir::ItemKind::Fn(ref sig, _, body_id) => { if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) { @@ -460,11 +452,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); - let Some(DocInfo { - empty: _, - doc_headers: headers, - }) = check_attrs(cx, &self.valid_idents, attrs) - else { + let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { return; }; if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { @@ -476,11 +464,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); - let Some(DocInfo { - empty: _, - doc_headers: headers, - }) = check_attrs(cx, &self.valid_idents, attrs) - else { + let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { return; }; if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) { @@ -522,12 +506,6 @@ struct DocHeaders { panics: bool, } -#[derive(Copy, Clone, Default)] -struct DocInfo { - empty: bool, - doc_headers: DocHeaders, -} - /// Does some pre-processing on raw, desugared `#[doc]` attributes such as parsing them and /// then delegates to `check_doc`. /// Some lints are already checked here if they can work with attributes directly and don't need @@ -535,7 +513,7 @@ struct DocInfo { /// Others are checked elsewhere, e.g. in `check_doc` if they need access to markdown, or /// back in the various late lint pass methods if they need the final doc headers, like "Safety" or /// "Panics" sections. -fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[Attribute]) -> Option { +fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[Attribute]) -> Option { /// We don't want the parser to choke on intra doc links. Since we don't /// actually care about rendering them, just pretend that all broken links /// point to a fake address. @@ -558,10 +536,8 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ doc.pop(); if doc.trim().is_empty() { - return Some(DocInfo { - empty: true, - doc_headers: DocHeaders::default(), - }); + empty_docs::check(cx, attrs); + return Some(DocHeaders::default()); } let mut cb = fake_broken_link_callback; @@ -570,18 +546,15 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION; let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb)); - Some(DocInfo { - empty: false, - doc_headers: check_doc( - cx, - valid_idents, - parser.into_offset_iter(), - Fragments { - fragments: &fragments, - doc: &doc, - }, - ), - }) + Some(check_doc( + cx, + valid_idents, + parser.into_offset_iter(), + Fragments { + fragments: &fragments, + doc: &doc, + }, + )) } const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail"]; From f066be7e1ed36e173edaf008c695420112966c8f Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 21:31:46 +0400 Subject: [PATCH 12/17] use span of fragments --- clippy_lints/src/doc/empty_docs.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/doc/empty_docs.rs b/clippy_lints/src/doc/empty_docs.rs index b0be71139616..84cbc3207f34 100644 --- a/clippy_lints/src/doc/empty_docs.rs +++ b/clippy_lints/src/doc/empty_docs.rs @@ -1,17 +1,13 @@ +use super::EMPTY_DOCS; use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::Attribute; use rustc_lint::LateContext; - -use super::EMPTY_DOCS; +use rustc_resolve::rustdoc::{attrs_to_doc_fragments, span_of_fragments}; // TODO: Adjust the parameters as necessary pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) { - let doc_attrs: Vec<_> = attrs.iter().filter(|attr| attr.doc_str().is_some()).collect(); - let span; - if let Some(first) = doc_attrs.first() - && let Some(last) = doc_attrs.last() - { - span = first.span.with_hi(last.span.hi()); + let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true); + if let Some(span) = span_of_fragments(&fragments) { span_lint_and_help( cx, EMPTY_DOCS, From d84d9d32f13baf4414430314d849ac051bff4468 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 22:33:16 +0400 Subject: [PATCH 13/17] lint on variant and fields as well --- clippy_lints/src/doc/mod.rs | 10 ++++ tests/ui/empty_docs.rs | 98 +++++++++++++++++++------------------ tests/ui/empty_docs.stderr | 64 ++++++++++++++++++------ 3 files changed, 109 insertions(+), 63 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 5690bd1d1ba3..76fd900bff3e 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 f5b4bb6736d1..c47a603e71b4 100644 --- a/tests/ui/empty_docs.rs +++ b/tests/ui/empty_docs.rs @@ -1,63 +1,67 @@ #![allow(unused)] #![warn(clippy::empty_docs)] +mod outer { + //! -/// this is a struct -struct Bananas { - /// count - count: usize, -} + /// this is a struct + struct Bananas { + /// count + count: usize, + } -/// -enum Warn { /// - A, - /// - B, -} + enum Warn { + /// + A, + B, + } -enum WarnA { - /// - A, - B, -} + enum DontWarn { + /// i + A, + B, + } -enum DontWarn { - /// it's ok - A, - /// - B, -} + #[doc = ""] + fn warn_about_this() {} -#[doc = ""] -fn warn_about_this() {} + #[doc = ""] + #[doc = ""] + fn this_doesn_warn() {} -#[doc = ""] -#[doc = ""] -fn this_doesn_warn() {} + #[doc = "a fine function"] + fn this_is_fine() {} -#[doc = "a fine function"] -fn this_is_fine() {} + /// + mod inner { + /// + fn dont_warn_inner_outer() { + //!w + } -fn warn_about_this_as_well() { - //! -} + fn this_is_ok() { + //! + //! inside the function + } -/// -fn warn_inner_outer() { - //!w -} + fn warn() { + /*! */ + } -fn this_is_ok() { - //! - //! inside the function -} + fn dont_warn() { + /*! dont warn me */ + } -fn warn() { - /*! */ -} + trait NoDoc { + /// + fn some() {} + } + } -fn dont_warn() { - /*! dont warn me */ + union Unite { + /// lint y + x: i32, + /// + y: i32, + } } - -trait NoDoc {} diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr index a2d8b986bf06..3f1d071fb13c 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 = ""] - | ^^^^^^^^^^^ +LL | /// + | ^^^ | = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:34:1 + --> tests/ui/empty_docs.rs:14:9 | -LL | / #[doc = ""] -LL | | #[doc = ""] - | |___________^ +LL | /// + | ^^^ | = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:42:5 + --> tests/ui/empty_docs.rs:25:5 | -LL | //! +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:56:5 + --> 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 | /*! */ - | ^^^^^^ +LL | /// + | ^^^ | = help: consider removing or filling it -error: aborting due to 5 previous errors +error: aborting due to 9 previous errors From ee50d5df90dc6cdeb266bf0965daf14799e0977b Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 22:52:44 +0400 Subject: [PATCH 14/17] correct wrong doc syntax --- clippy_lints/src/manual_is_ascii_check.rs | 2 +- clippy_lints/src/methods/filter_map.rs | 2 +- clippy_lints/src/question_mark.rs | 6 +++--- clippy_lints/src/slow_vector_initialization.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/manual_is_ascii_check.rs b/clippy_lints/src/manual_is_ascii_check.rs index e433c5a3b32b..338a299740a8 100644 --- a/clippy_lints/src/manual_is_ascii_check.rs +++ b/clippy_lints/src/manual_is_ascii_check.rs @@ -74,7 +74,7 @@ enum CharRange { LowerChar, /// 'A'..='Z' | b'A'..=b'Z' UpperChar, - /// AsciiLower | AsciiUpper + /// `AsciiLower` | `AsciiUpper` FullChar, /// '0..=9' Digit, diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index e489899c19e3..9b656531957f 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -75,7 +75,7 @@ enum OffendingFilterExpr<'tcx> { }, /// `.filter(|enum| matches!(enum, Enum::A(_)))` Matches { - /// The DefId of the variant being matched + /// The `DefId` of the variant being matched variant_def_id: hir::def_id::DefId, }, } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index b5da27d7993b..6bd90ebd97ae 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -74,12 +74,12 @@ impl QuestionMark { enum IfBlockType<'hir> { /// An `if x.is_xxx() { a } else { b } ` expression. /// - /// Contains: caller (x), caller_type, call_sym (is_xxx), if_then (a), if_else (b) + /// Contains: `caller (x), caller_type, call_sym (is_xxx), if_then (a), if_else (b)` IfIs(&'hir Expr<'hir>, Ty<'hir>, Symbol, &'hir Expr<'hir>), /// An `if let Xxx(a) = b { c } else { d }` expression. /// - /// Contains: let_pat_qpath (Xxx), let_pat_type, let_pat_sym (a), let_expr (b), if_then (c), - /// if_else (d) + /// Contains: `let_pat_qpath (Xxx), let_pat_type, let_pat_sym (a), let_expr (b), if_then (c), + /// if_else (d)` IfLet( Res, Ty<'hir>, diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index c4a5e48e855e..4837f2858a66 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -62,7 +62,7 @@ declare_lint_pass!(SlowVectorInit => [SLOW_VECTOR_INITIALIZATION]); /// assigned to a variable. For example, `let mut vec = Vec::with_capacity(0)` or /// `vec = Vec::with_capacity(0)` struct VecAllocation<'tcx> { - /// HirId of the variable + /// `HirId` of the variable local_id: HirId, /// Reference to the expression which allocates the vector From 5152050c5f8d1aa18f43b32dad5f1364ecb859a5 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Sun, 25 Feb 2024 23:17:03 +0400 Subject: [PATCH 15/17] move lint directly into check_attrs --- clippy_lints/src/doc/empty_docs.rs | 20 -------------------- clippy_lints/src/doc/mod.rs | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 clippy_lints/src/doc/empty_docs.rs diff --git a/clippy_lints/src/doc/empty_docs.rs b/clippy_lints/src/doc/empty_docs.rs deleted file mode 100644 index 84cbc3207f34..000000000000 --- a/clippy_lints/src/doc/empty_docs.rs +++ /dev/null @@ -1,20 +0,0 @@ -use super::EMPTY_DOCS; -use clippy_utils::diagnostics::span_lint_and_help; -use rustc_ast::Attribute; -use rustc_lint::LateContext; -use rustc_resolve::rustdoc::{attrs_to_doc_fragments, span_of_fragments}; - -// TODO: Adjust the parameters as necessary -pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) { - let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true); - if let Some(span) = span_of_fragments(&fragments) { - span_lint_and_help( - cx, - EMPTY_DOCS, - span, - "empty doc comment", - None, - "consider removing or filling it", - ); - } -} diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 76fd900bff3e..4a253e9fd6cf 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -19,7 +19,8 @@ use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self}; use rustc_resolve::rustdoc::{ - add_doc_fragment, attrs_to_doc_fragments, main_body_opts, source_span_for_markdown_range, DocFragment, + add_doc_fragment, attrs_to_doc_fragments, main_body_opts, source_span_for_markdown_range, span_of_fragments, + DocFragment, }; use rustc_session::impl_lint_pass; use rustc_span::edition::Edition; @@ -27,7 +28,6 @@ use rustc_span::{sym, Span}; use std::ops::Range; use url::Url; -mod empty_docs; mod link_with_quotes; mod markdown; mod missing_headers; @@ -546,7 +546,16 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ doc.pop(); if doc.trim().is_empty() { - empty_docs::check(cx, attrs); + if let Some(span) = span_of_fragments(&fragments) { + span_lint_and_help( + cx, + EMPTY_DOCS, + span, + "empty doc comment", + None, + "consider removing or filling it", + ); + } return Some(DocHeaders::default()); } From 93deced5531562a43048f59f853307749574a631 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Mon, 26 Feb 2024 07:02:40 +0400 Subject: [PATCH 16/17] change rs doc to no_run --- clippy_lints/src/doc/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 4a253e9fd6cf..639179a070db 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -345,14 +345,14 @@ declare_clippy_lint! { /// ### Why is this bad? /// It is unlikely that there is any reason to have empty documentation for an item /// ### Example - /// ```rs + /// ```no_run /// /// /// fn returns_true() -> bool { /// true /// } /// ``` /// Use instead: - /// ```rs + /// ```no_run /// fn returns_true() -> bool { /// true /// } From fca77c0976f387bb383d572ab82aa53b0c64ee6c Mon Sep 17 00:00:00 2001 From: lucarlig Date: Mon, 26 Feb 2024 19:15:44 +0400 Subject: [PATCH 17/17] docs and imports --- clippy_lints/src/doc/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 639179a070db..9af34c3a7bf0 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -17,7 +17,7 @@ use rustc_hir::{AnonConst, Expr}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self}; +use rustc_middle::ty; use rustc_resolve::rustdoc::{ add_doc_fragment, attrs_to_doc_fragments, main_body_opts, source_span_for_markdown_range, span_of_fragments, DocFragment, @@ -343,7 +343,7 @@ declare_clippy_lint! { /// ### What it does /// Detects documentation that is empty. /// ### Why is this bad? - /// It is unlikely that there is any reason to have empty documentation for an item + /// Empty docs clutter code without adding value, reducing readability and maintainability. /// ### Example /// ```no_run /// ///