From dc38e3f5be522363c0681048e9936d119134976e Mon Sep 17 00:00:00 2001 From: John Arundel Date: Thu, 23 May 2024 10:35:00 +0100 Subject: [PATCH 1/6] [ mut_range_bound ]: fix doc nits --- clippy_lints/src/loops/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index 086829421530..64ea591993da 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -356,10 +356,10 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for loops which have a range bound that is a mutable variable + /// Checks for loops with a range bound that is a mutable variable. /// /// ### Why is this bad? - /// One might think that modifying the mutable variable changes the loop bounds + /// One might think that modifying the mutable variable changes the loop bounds. It doesn't. /// /// ### Known problems /// False positive when mutation is followed by a `break`, but the `break` is not immediately @@ -381,7 +381,7 @@ declare_clippy_lint! { /// let mut foo = 42; /// for i in 0..foo { /// foo -= 1; - /// println!("{}", i); // prints numbers from 0 to 42, not 0 to 21 + /// println!("{i}"); // prints numbers from 0 to 41, not 0 to 21 /// } /// ``` #[clippy::version = "pre 1.29.0"] From c95a575b90e474a645d5eb55069a99d52a4c205d Mon Sep 17 00:00:00 2001 From: John Arundel Date: Thu, 23 May 2024 11:53:56 +0100 Subject: [PATCH 2/6] [ allow_attributes_without_reason ]: fix doc nits --- clippy_lints/src/attrs/mod.rs | 44 +++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs index 83c828e8e223..332a78712aa2 100644 --- a/clippy_lints/src/attrs/mod.rs +++ b/clippy_lints/src/attrs/mod.rs @@ -270,13 +270,49 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for attributes that allow lints without a reason. + /// Checks for cfg attributes having operating systems used in target family position. /// - /// (This requires the `lint_reasons` feature) + /// ### Why is this bad? + /// The configuration option will not be recognised and the related item will not be included + /// by the conditional compilation engine. + /// + /// ### Example + /// ```no_run + /// #[cfg(linux)] + /// fn conditional() { } + /// ``` + /// + /// Use instead: + /// ```no_run + /// # mod hidden { + /// #[cfg(target_os = "linux")] + /// fn conditional() { } + /// # } + /// + /// // or + /// + /// #[cfg(unix)] + /// fn conditional() { } + /// ``` + /// Check the [Rust Reference](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os) for more details. + #[clippy::version = "1.45.0"] + pub MISMATCHED_TARGET_OS, + correctness, + "usage of `cfg(operating_system)` instead of `cfg(target_os = \"operating_system\")`" +} + +declare_clippy_lint! { + /// ### What it does + /// Checks for attributes that allow lints without specifying the reason + /// they should be allowed. + /// + /// (This requires the `lint_reasons` feature.) /// /// ### Why restrict this? - /// Justifying each `allow` helps readers understand the reasoning, - /// and may allow removing `allow` attributes if their purpose is obsolete. + /// There should always be a specific reason to allow a lint. This reason + /// should be documented using the `reason` parameter, so that readers can + /// understand why the `allow` is required, or remove it if it's no + /// longer needed. /// /// ### Example /// ```no_run From bc3af6b1a92b4e123ea0bb3831b1fc67dc5be149 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Thu, 23 May 2024 11:41:39 +0100 Subject: [PATCH 3/6] [ allow_attributes ]: fix doc nits --- clippy_lints/src/allow_attributes.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/allow_attributes.rs b/clippy_lints/src/allow_attributes.rs index 123d0e51eeee..990f724ab9d9 100644 --- a/clippy_lints/src/allow_attributes.rs +++ b/clippy_lints/src/allow_attributes.rs @@ -10,20 +10,19 @@ use rustc_session::declare_lint_pass; declare_clippy_lint! { /// ### What it does /// Checks for usage of the `#[allow]` attribute and suggests replacing it with - /// the `#[expect]` (See [RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html)) + /// `#[expect]`. (See [RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html)) /// - /// The expect attribute is still unstable and requires the `lint_reasons` + /// The expect attribute is still unstable and requires the `lint_reasons` feature /// on nightly. It can be enabled by adding `#![feature(lint_reasons)]` to /// the crate root. /// - /// This lint only warns outer attributes (`#[allow]`), as inner attributes + /// This lint only warns on outer attributes (`#[allow]`), as inner attributes /// (`#![allow]`) are usually used to enable or disable lints on a global scale. /// /// ### Why restrict this? - /// `#[allow]` attributes can linger after their reason for existence is gone. - /// `#[expect]` attributes suppress the lint emission, but emit a warning if - /// the expectation is unfulfilled. This can be useful to be notified when the - /// lint is no longer triggered, which may indicate the attribute can be removed. + /// The `#[allow]` attribute does not warn when the expected lint is no longer triggered, + /// whereas `#[expect]` calls attention to this fact. This can be a useful reminder to + /// remove attributes that are no longer needed. /// /// ### Example /// ```rust,ignore From 942efe5476ab511efc8e1443d208d0ca4e803be7 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Thu, 23 May 2024 11:32:18 +0100 Subject: [PATCH 4/6] [ arc_with_non_send_sync ]: fix doc nits --- clippy_lints/src/arc_with_non_send_sync.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/arc_with_non_send_sync.rs b/clippy_lints/src/arc_with_non_send_sync.rs index 389338973894..d57ab539fff4 100644 --- a/clippy_lints/src/arc_with_non_send_sync.rs +++ b/clippy_lints/src/arc_with_non_send_sync.rs @@ -17,7 +17,7 @@ declare_clippy_lint! { /// `Arc` is a thread-safe `Rc` and guarantees that updates to the reference counter /// use atomic operations. To send an `Arc` across thread boundaries and /// share ownership between multiple threads, `T` must be [both `Send` and `Sync`](https://doc.rust-lang.org/std/sync/struct.Arc.html#thread-safety), - /// so either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc` + /// so either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc`. /// /// ### Example /// ```no_run From af73aebfc33a41df3b2f6188849b4530022ce0b3 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Thu, 23 May 2024 10:39:52 +0100 Subject: [PATCH 5/6] [ needless_for_each ]: fix doc nits --- clippy_lints/src/needless_for_each.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 630018238f4c..28910767840f 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -31,8 +31,8 @@ declare_clippy_lint! { /// Use instead: /// ```no_run /// let v = vec![0, 1, 2]; - /// for elem in v.iter() { - /// println!("{}", elem); + /// for elem in v { + /// println!("{elem}"); /// } /// ``` /// From 1ec83813637ce16f5b091a1472630a97bb4b3f1f Mon Sep 17 00:00:00 2001 From: John Arundel Date: Mon, 3 Jun 2024 12:21:42 +0100 Subject: [PATCH 6/6] update declared lints --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0f511742fa1..727c64106a6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5520,6 +5520,7 @@ Released 2018-09-13 [`min_max`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_max [`misaligned_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#misaligned_transmute [`mismatched_target_os`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatched_target_os +[`mismatched_target_os`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatched_target_os [`mismatching_type_param_order`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatching_type_param_order [`misnamed_getters`]: https://rust-lang.github.io/rust-clippy/master/index.html#misnamed_getters [`misrefactored_assign_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#misrefactored_assign_op diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index a4948e36fbe2..d277b49f825d 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -58,6 +58,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::attrs::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO, crate::attrs::EMPTY_LINE_AFTER_OUTER_ATTR_INFO, crate::attrs::INLINE_ALWAYS_INFO, + crate::attrs::MISMATCHED_TARGET_OS_INFO, crate::attrs::MIXED_ATTRIBUTES_STYLE_INFO, crate::attrs::NON_MINIMAL_CFG_INFO, crate::attrs::SHOULD_PANIC_WITHOUT_EXPECT_INFO,