diff options
| author | dswij <dharmasw@outlook.com> | 2025-02-07 17:34:21 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-07 17:34:21 +0000 |
| commit | 4e5d00a0a729e7783701ea93edefde1aa3908b59 (patch) | |
| tree | d12549976182c84ce1e4da032f2d944e47eaeccf /tests | |
| parent | 0d3bf65bd45435c91a776972b7da8500562c2fe1 (diff) | |
| parent | a03242f8e0e7ac1d15b2e78568dcbb5e92e9f258 (diff) | |
| download | rust-4e5d00a0a729e7783701ea93edefde1aa3908b59.tar.gz rust-4e5d00a0a729e7783701ea93edefde1aa3908b59.zip | |
Deprecate redundant lint `option_map_or_err_ok` and take `manual_ok_or` out of pedantic (#14027)
While extending the `option_map_or_err_ok` lint (warn by default,
"style") to recognize η-expanded forms of `Ok`, as in
```rust
// Should suggest `opt.ok_or("foobar")`
let _ = opt.map_or(Err("foobar"), |x| Ok(x));
```
I discovered that the `manual_ok_or` lint (allow by default, "pedantic")
already covered exactly the cases handled by `option_map_or_err_ok`,
including the one I was adding. Apparently, `option_map_or_err_ok` was
added without realizing that the lint already existed under the
`manual_ok_or` name. As a matter of fact, artifacts of this second lint
were even present in the first lint `stderr` file and went unnoticed for
more than a year.
This PR:
- deprecates `option_map_or_err_ok` with a message saying to use
`manual_ok_or`
- moves `manual_ok_or` from "pedantic" to "style" (the category in which
`option_map_or_err_ok` was)
In addition, I think that this lint, which is short, machine applicable,
and leads to shorter and clearer code with less arguments (`Ok`
disappears) and the removal of one level of call (`Err(x)` is replaced
by `x`), is a reason by itself to be in "style".
changelog: [`option_map_or_err_ok` and `manual_ok_or`]: move
`manual_ok_or` from "pedantic" to "style", and deprecate the redundant
style lint `option_map_or_err_ok`.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/deprecated.rs | 1 | ||||
| -rw-r--r-- | tests/ui/deprecated.stderr | 8 | ||||
| -rw-r--r-- | tests/ui/manual_ok_or.stderr | 11 | ||||
| -rw-r--r-- | tests/ui/option_map_or_err_ok.fixed | 7 | ||||
| -rw-r--r-- | tests/ui/option_map_or_err_ok.rs | 7 | ||||
| -rw-r--r-- | tests/ui/option_map_or_err_ok.stderr | 11 |
6 files changed, 9 insertions, 36 deletions
diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index 5617db90a47..35646e1c239 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -15,5 +15,6 @@ #![warn(clippy::regex_macro)] //~ ERROR: lint `clippy::regex_macro` #![warn(clippy::pub_enum_variant_names)] //~ ERROR: lint `clippy::pub_enum_variant_names` #![warn(clippy::wrong_pub_self_convention)] //~ ERROR: lint `clippy::wrong_pub_self_convention` +#![warn(clippy::option_map_or_err_ok)] //~ ERROR: lint `clippy::option_map_or_err_ok` fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index b3e1646c804..d7be1e583b0 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -79,5 +79,11 @@ error: lint `clippy::wrong_pub_self_convention` has been removed: `clippy::wrong LL | #![warn(clippy::wrong_pub_self_convention)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 13 previous errors +error: lint `clippy::option_map_or_err_ok` has been removed: `clippy::manual_ok_or` covers this case + --> tests/ui/deprecated.rs:18:9 + | +LL | #![warn(clippy::option_map_or_err_ok)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 14 previous errors diff --git a/tests/ui/manual_ok_or.stderr b/tests/ui/manual_ok_or.stderr index 2441a75b5c4..4722f53580f 100644 --- a/tests/ui/manual_ok_or.stderr +++ b/tests/ui/manual_ok_or.stderr @@ -13,15 +13,6 @@ error: this pattern reimplements `Option::ok_or` LL | foo.map_or(Err("error"), Ok); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` -error: called `map_or(Err(_), Ok)` on an `Option` value - --> tests/ui/manual_ok_or.rs:14:5 - | -LL | foo.map_or(Err("error"), Ok); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `ok_or`: `foo.ok_or("error")` - | - = note: `-D clippy::option-map-or-err-ok` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::option_map_or_err_ok)]` - error: this pattern reimplements `Option::ok_or` --> tests/ui/manual_ok_or.rs:17:5 | @@ -47,5 +38,5 @@ LL + "{}{}{}{}{}{}{}", LL ~ "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer")); | -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors diff --git a/tests/ui/option_map_or_err_ok.fixed b/tests/ui/option_map_or_err_ok.fixed deleted file mode 100644 index 131f4b2093e..00000000000 --- a/tests/ui/option_map_or_err_ok.fixed +++ /dev/null @@ -1,7 +0,0 @@ -#![warn(clippy::option_map_or_err_ok)] - -fn main() { - let x = Some("a"); - let _ = x.ok_or("a"); - //~^ ERROR: called `map_or(Err(_), Ok)` on an `Option` value -} diff --git a/tests/ui/option_map_or_err_ok.rs b/tests/ui/option_map_or_err_ok.rs deleted file mode 100644 index 0f07a592ae5..00000000000 --- a/tests/ui/option_map_or_err_ok.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![warn(clippy::option_map_or_err_ok)] - -fn main() { - let x = Some("a"); - let _ = x.map_or(Err("a"), Ok); - //~^ ERROR: called `map_or(Err(_), Ok)` on an `Option` value -} diff --git a/tests/ui/option_map_or_err_ok.stderr b/tests/ui/option_map_or_err_ok.stderr deleted file mode 100644 index 1971af80aa8..00000000000 --- a/tests/ui/option_map_or_err_ok.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: called `map_or(Err(_), Ok)` on an `Option` value - --> tests/ui/option_map_or_err_ok.rs:5:13 - | -LL | let _ = x.map_or(Err("a"), Ok); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `ok_or`: `x.ok_or("a")` - | - = note: `-D clippy::option-map-or-err-ok` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::option_map_or_err_ok)]` - -error: aborting due to 1 previous error - |
