diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index 04912120e27..b7b5f059de6 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -159,6 +159,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(methods::MANUAL_SPLIT_ONCE), LintId::of(methods::MANUAL_STR_REPEAT), LintId::of(methods::MAP_COLLECT_RESULT_UNIT), + LintId::of(methods::MAP_FLATTEN), LintId::of(methods::MAP_IDENTITY), LintId::of(methods::NEEDLESS_SPLITN), LintId::of(methods::NEW_RET_NO_SELF), diff --git a/clippy_lints/src/lib.register_complexity.rs b/clippy_lints/src/lib.register_complexity.rs index dcc95cf6c07..a21ddf73a11 100644 --- a/clippy_lints/src/lib.register_complexity.rs +++ b/clippy_lints/src/lib.register_complexity.rs @@ -41,6 +41,7 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec! LintId::of(methods::MANUAL_FILTER_MAP), LintId::of(methods::MANUAL_FIND_MAP), LintId::of(methods::MANUAL_SPLIT_ONCE), + LintId::of(methods::MAP_FLATTEN), LintId::of(methods::MAP_IDENTITY), LintId::of(methods::NEEDLESS_SPLITN), LintId::of(methods::OPTION_AS_REF_DEREF), diff --git a/clippy_lints/src/lib.register_pedantic.rs b/clippy_lints/src/lib.register_pedantic.rs index 5ee7799f9c5..70a4a624378 100644 --- a/clippy_lints/src/lib.register_pedantic.rs +++ b/clippy_lints/src/lib.register_pedantic.rs @@ -63,7 +63,6 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![ LintId::of(methods::FROM_ITER_INSTEAD_OF_COLLECT), LintId::of(methods::IMPLICIT_CLONE), LintId::of(methods::INEFFICIENT_TO_STRING), - LintId::of(methods::MAP_FLATTEN), LintId::of(methods::MAP_UNWRAP_OR), LintId::of(misc::FLOAT_CMP), LintId::of(misc::USED_UNDERSCORE_BINDING), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a325da75ba6..ad6fb0c613b 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -543,7 +543,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.31.0"] pub MAP_FLATTEN, - pedantic, + complexity, "using combinations of `flatten` and `map` which can usually be written as a single method call" } diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs index 642c77460a3..0141fb7856d 100644 --- a/tests/ui/option_env_unwrap.rs +++ b/tests/ui/option_env_unwrap.rs @@ -1,5 +1,6 @@ // aux-build:macro_rules.rs #![warn(clippy::option_env_unwrap)] +#![allow(clippy::map_flatten)] #[macro_use] extern crate macro_rules; diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index e6a58b0b2b7..885ac096cc8 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -1,5 +1,5 @@ error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:17:13 + --> $DIR/option_env_unwrap.rs:18:13 | LL | let _ = option_env!("PATH").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | let _ = option_env!("PATH").unwrap(); = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:18:13 + --> $DIR/option_env_unwrap.rs:19:13 | LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:9:9 + --> $DIR/option_env_unwrap.rs:10:9 | LL | option_env!($env).unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | let _ = option_env_unwrap!("PATH"); = note: this error originates in the macro `option_env_unwrap` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:12:9 + --> $DIR/option_env_unwrap.rs:13:9 | LL | option_env!($env).expect($message) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let _ = option_env_unwrap!("PATH", "environment variable PATH isn't set = note: this error originates in the macro `option_env_unwrap` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:21:13 + --> $DIR/option_env_unwrap.rs:22:13 | LL | let _ = option_env_unwrap_external!("PATH"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = option_env_unwrap_external!("PATH"); = note: this error originates in the macro `option_env_unwrap_external` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:22:13 + --> $DIR/option_env_unwrap.rs:23:13 | LL | let _ = option_env_unwrap_external!("PATH", "environment variable PATH isn't set"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/option_filter_map.fixed b/tests/ui/option_filter_map.fixed index f9d1825ade0..b20f73f3110 100644 --- a/tests/ui/option_filter_map.fixed +++ b/tests/ui/option_filter_map.fixed @@ -1,8 +1,6 @@ -#![warn(clippy::option_filter_map)] // run-rustfix -fn odds_out(x: i32) -> Option { - if x % 2 == 0 { Some(x) } else { None } -} +#![warn(clippy::option_filter_map)] +#![allow(clippy::map_flatten)] fn main() { let _ = Some(Some(1)).flatten(); @@ -21,3 +19,7 @@ fn main() { .map(odds_out) .flatten(); } + +fn odds_out(x: i32) -> Option { + if x % 2 == 0 { Some(x) } else { None } +} diff --git a/tests/ui/option_filter_map.rs b/tests/ui/option_filter_map.rs index 588e1ccccce..7abaaa0fb83 100644 --- a/tests/ui/option_filter_map.rs +++ b/tests/ui/option_filter_map.rs @@ -1,8 +1,6 @@ -#![warn(clippy::option_filter_map)] // run-rustfix -fn odds_out(x: i32) -> Option { - if x % 2 == 0 { Some(x) } else { None } -} +#![warn(clippy::option_filter_map)] +#![allow(clippy::map_flatten)] fn main() { let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); @@ -23,3 +21,7 @@ fn main() { .filter(|o| o.is_some()) .map(|o| o.unwrap()); } + +fn odds_out(x: i32) -> Option { + if x % 2 == 0 { Some(x) } else { None } +} diff --git a/tests/ui/option_filter_map.stderr b/tests/ui/option_filter_map.stderr index 31a82969d5a..4a030ac9ab0 100644 --- a/tests/ui/option_filter_map.stderr +++ b/tests/ui/option_filter_map.stderr @@ -1,5 +1,5 @@ error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:8:27 + --> $DIR/option_filter_map.rs:6:27 | LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` @@ -7,37 +7,37 @@ LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); = note: `-D clippy::option-filter-map` implied by `-D warnings` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:9:27 + --> $DIR/option_filter_map.rs:7:27 | LL | let _ = Some(Some(1)).filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:10:35 + --> $DIR/option_filter_map.rs:8:35 | LL | let _ = Some(1).map(odds_out).filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:11:35 + --> $DIR/option_filter_map.rs:9:35 | LL | let _ = Some(1).map(odds_out).filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:13:39 + --> $DIR/option_filter_map.rs:11:39 | LL | let _ = vec![Some(1)].into_iter().filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:14:39 + --> $DIR/option_filter_map.rs:12:39 | LL | let _ = vec![Some(1)].into_iter().filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:18:10 + --> $DIR/option_filter_map.rs:16:10 | LL | .filter(Option::is_some) | __________^ @@ -45,7 +45,7 @@ LL | | .map(Option::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:23:10 + --> $DIR/option_filter_map.rs:21:10 | LL | .filter(|o| o.is_some()) | __________^