From bffb664fbf094f53d51bec66d1b042265db1cbad Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Thu, 16 Nov 2023 10:11:13 -0800 Subject: [PATCH 1/2] Fix markup in recent lint documentation. Also make the examples more realistic by hiding the `;`s so as not to visibly be discarding the computed value. --- clippy_lints/src/methods/mod.rs | 8 +++++--- clippy_lints/src/unnecessary_map_on_constructor.rs | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 57c3913944f..3166a33fc2f 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3609,7 +3609,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for usage of `as_str()` on a `String`` chained with a method available on the `String` itself. + /// Checks for usage of `as_str()` on a `String` chained with a method available on the `String` itself. /// /// ### Why is this bad? /// The `as_str()` conversion is pointless and can be removed for simplicity and cleanliness. @@ -3618,14 +3618,16 @@ declare_clippy_lint! { /// ```no_run /// # #![allow(unused)] /// let owned_string = "This is a string".to_owned(); - /// owned_string.as_str().as_bytes(); + /// owned_string.as_str().as_bytes() + /// # ; /// ``` /// /// Use instead: /// ```no_run /// # #![allow(unused)] /// let owned_string = "This is a string".to_owned(); - /// owned_string.as_bytes(); + /// owned_string.as_bytes() + /// # ; /// ``` #[clippy::version = "1.74.0"] pub REDUNDANT_AS_STR, diff --git a/clippy_lints/src/unnecessary_map_on_constructor.rs b/clippy_lints/src/unnecessary_map_on_constructor.rs index 3a6d0895c72..39a83bfa005 100644 --- a/clippy_lints/src/unnecessary_map_on_constructor.rs +++ b/clippy_lints/src/unnecessary_map_on_constructor.rs @@ -9,19 +9,22 @@ use rustc_span::sym; declare_clippy_lint! { /// ### What it does - /// Suggest removing the use of a map (or map_err) method when an Option or Result is being constructed. + /// Suggests removing the use of a `map()` (or `map_err()`) method when an `Option` or `Result` + /// is being constructed. /// /// ### Why is this bad? /// It introduces unnecessary complexity. In this case the function can be used directly and - /// construct the Option or Result from the output. + /// construct the `Option` or `Result` from the output. /// /// ### Example /// ```no_run - /// Some(4).map(i32::swap_bytes); + /// Some(4).map(i32::swap_bytes) + /// # ; /// ``` /// Use instead: /// ```no_run - /// Some(i32::swap_bytes(4)); + /// Some(i32::swap_bytes(4)) + /// # ; /// ``` #[clippy::version = "1.74.0"] pub UNNECESSARY_MAP_ON_CONSTRUCTOR, From b3f4a9015c9ee118574bb9d3419b874826552c24 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Sat, 18 Nov 2023 10:53:03 -0800 Subject: [PATCH 2/2] Remove space and rephrase `map()` advice. --- clippy_lints/src/unnecessary_map_on_constructor.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/unnecessary_map_on_constructor.rs b/clippy_lints/src/unnecessary_map_on_constructor.rs index 39a83bfa005..5c880288430 100644 --- a/clippy_lints/src/unnecessary_map_on_constructor.rs +++ b/clippy_lints/src/unnecessary_map_on_constructor.rs @@ -10,11 +10,11 @@ use rustc_span::sym; declare_clippy_lint! { /// ### What it does /// Suggests removing the use of a `map()` (or `map_err()`) method when an `Option` or `Result` - /// is being constructed. + /// is being constructed. /// /// ### Why is this bad? - /// It introduces unnecessary complexity. In this case the function can be used directly and - /// construct the `Option` or `Result` from the output. + /// It introduces unnecessary complexity. Instead, the function can be called before + /// constructing the `Option` or `Result` from its return value. /// /// ### Example /// ```no_run