mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-22 20:53:21 +00:00
Auto merge of #8054 - camsteffen:map-flatten-style, r=giraffate
Upgrade map_flatten to complexity changelog: upgrade [`map_flatten`] to complexity Resolves #7999
This commit is contained in:
commit
9eabec9f07
9 changed files with 30 additions and 24 deletions
|
@ -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),
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// aux-build:macro_rules.rs
|
||||
#![warn(clippy::option_env_unwrap)]
|
||||
#![allow(clippy::map_flatten)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate macro_rules;
|
||||
|
|
|
@ -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");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#![warn(clippy::option_filter_map)]
|
||||
// run-rustfix
|
||||
fn odds_out(x: i32) -> Option<i32> {
|
||||
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<i32> {
|
||||
if x % 2 == 0 { Some(x) } else { None }
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#![warn(clippy::option_filter_map)]
|
||||
// run-rustfix
|
||||
fn odds_out(x: i32) -> Option<i32> {
|
||||
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<i32> {
|
||||
if x % 2 == 0 { Some(x) } else { None }
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
| __________^
|
||||
|
|
Loading…
Reference in a new issue