Skip to content

Commit 4e5d00a

Browse files
authored
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`.
2 parents 0d3bf65 + a03242f commit 4e5d00a

10 files changed

+12
-107
lines changed

clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ pub static LINTS: &[&crate::LintInfo] = &[
452452
crate::methods::OPTION_AS_REF_CLONED_INFO,
453453
crate::methods::OPTION_AS_REF_DEREF_INFO,
454454
crate::methods::OPTION_FILTER_MAP_INFO,
455-
crate::methods::OPTION_MAP_OR_ERR_OK_INFO,
456455
crate::methods::OPTION_MAP_OR_NONE_INFO,
457456
crate::methods::OR_FUN_CALL_INFO,
458457
crate::methods::OR_THEN_UNWRAP_INFO,

clippy_lints/src/deprecated_lints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[
4040
("clippy::pub_enum_variant_names", "`clippy::enum_variant_names` now covers this case via the `avoid-breaking-exported-api` config"),
4141
#[clippy::version = "1.54.0"]
4242
("clippy::wrong_pub_self_convention", "`clippy::wrong_self_convention` now covers this case via the `avoid-breaking-exported-api` config"),
43+
#[clippy::version = "1.86.0"]
44+
("clippy::option_map_or_err_ok", "`clippy::manual_ok_or` covers this case"),
4345
// end deprecated lints. used by `cargo dev deprecate_lint`
4446
]}
4547

clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ mod ok_expect;
8282
mod open_options;
8383
mod option_as_ref_cloned;
8484
mod option_as_ref_deref;
85-
mod option_map_or_err_ok;
8685
mod option_map_or_none;
8786
mod option_map_unwrap_or;
8887
mod or_fun_call;
@@ -2641,7 +2640,7 @@ declare_clippy_lint! {
26412640
/// ```
26422641
#[clippy::version = "1.49.0"]
26432642
pub MANUAL_OK_OR,
2644-
pedantic,
2643+
style,
26452644
"finds patterns that can be encoded more concisely with `Option::ok_or`"
26462645
}
26472646

@@ -3783,31 +3782,6 @@ declare_clippy_lint! {
37833782
"calls to `Path::join` which will overwrite the original path"
37843783
}
37853784

3786-
declare_clippy_lint! {
3787-
/// ### What it does
3788-
/// Checks for usage of `_.map_or(Err(_), Ok)`.
3789-
///
3790-
/// ### Why is this bad?
3791-
/// Readability, this can be written more concisely as
3792-
/// `_.ok_or(_)`.
3793-
///
3794-
/// ### Example
3795-
/// ```no_run
3796-
/// # let opt = Some(1);
3797-
/// opt.map_or(Err("error"), Ok);
3798-
/// ```
3799-
///
3800-
/// Use instead:
3801-
/// ```no_run
3802-
/// # let opt = Some(1);
3803-
/// opt.ok_or("error");
3804-
/// ```
3805-
#[clippy::version = "1.76.0"]
3806-
pub OPTION_MAP_OR_ERR_OK,
3807-
style,
3808-
"using `Option.map_or(Err(_), Ok)`, which is more succinctly expressed as `Option.ok_or(_)`"
3809-
}
3810-
38113785
declare_clippy_lint! {
38123786
/// ### What it does
38133787
/// Checks for iterators of `Result`s using `.filter(Result::is_ok).map(Result::unwrap)` that may
@@ -4579,7 +4553,6 @@ impl_lint_pass!(Methods => [
45794553
WAKER_CLONE_WAKE,
45804554
UNNECESSARY_FALLIBLE_CONVERSIONS,
45814555
JOIN_ABSOLUTE_PATHS,
4582-
OPTION_MAP_OR_ERR_OK,
45834556
RESULT_FILTER_MAP,
45844557
ITER_FILTER_IS_SOME,
45854558
ITER_FILTER_IS_OK,
@@ -5146,7 +5119,6 @@ impl Methods {
51465119
("map_or", [def, map]) => {
51475120
option_map_or_none::check(cx, expr, recv, def, map);
51485121
manual_ok_or::check(cx, expr, recv, def, map);
5149-
option_map_or_err_ok::check(cx, expr, recv, def, map);
51505122
unnecessary_map_or::check(cx, expr, recv, def, map, span, &self.msrv);
51515123
},
51525124
("map_or_else", [def, map]) => {

clippy_lints/src/methods/option_map_or_err_ok.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

tests/ui/deprecated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
#![warn(clippy::regex_macro)] //~ ERROR: lint `clippy::regex_macro`
1616
#![warn(clippy::pub_enum_variant_names)] //~ ERROR: lint `clippy::pub_enum_variant_names`
1717
#![warn(clippy::wrong_pub_self_convention)] //~ ERROR: lint `clippy::wrong_pub_self_convention`
18+
#![warn(clippy::option_map_or_err_ok)] //~ ERROR: lint `clippy::option_map_or_err_ok`
1819

1920
fn main() {}

tests/ui/deprecated.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,11 @@ error: lint `clippy::wrong_pub_self_convention` has been removed: `clippy::wrong
7979
LL | #![warn(clippy::wrong_pub_self_convention)]
8080
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8181

82-
error: aborting due to 13 previous errors
82+
error: lint `clippy::option_map_or_err_ok` has been removed: `clippy::manual_ok_or` covers this case
83+
--> tests/ui/deprecated.rs:18:9
84+
|
85+
LL | #![warn(clippy::option_map_or_err_ok)]
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
88+
error: aborting due to 14 previous errors
8389

tests/ui/manual_ok_or.stderr

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ error: this pattern reimplements `Option::ok_or`
1313
LL | foo.map_or(Err("error"), Ok);
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")`
1515

16-
error: called `map_or(Err(_), Ok)` on an `Option` value
17-
--> tests/ui/manual_ok_or.rs:14:5
18-
|
19-
LL | foo.map_or(Err("error"), Ok);
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `ok_or`: `foo.ok_or("error")`
21-
|
22-
= note: `-D clippy::option-map-or-err-ok` implied by `-D warnings`
23-
= help: to override `-D warnings` add `#[allow(clippy::option_map_or_err_ok)]`
24-
2516
error: this pattern reimplements `Option::ok_or`
2617
--> tests/ui/manual_ok_or.rs:17:5
2718
|
@@ -47,5 +38,5 @@ LL + "{}{}{}{}{}{}{}",
4738
LL ~ "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer"));
4839
|
4940

50-
error: aborting due to 5 previous errors
41+
error: aborting due to 4 previous errors
5142

tests/ui/option_map_or_err_ok.fixed

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/ui/option_map_or_err_ok.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/ui/option_map_or_err_ok.stderr

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)