Skip to content

Commit 9eabec9

Browse files
committed
Auto merge of #8054 - camsteffen:map-flatten-style, r=giraffate
Upgrade map_flatten to complexity changelog: upgrade [`map_flatten`] to complexity Resolves #7999
2 parents 3cd151d + de9de4f commit 9eabec9

9 files changed

+30
-24
lines changed

clippy_lints/src/lib.register_all.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
159159
LintId::of(methods::MANUAL_SPLIT_ONCE),
160160
LintId::of(methods::MANUAL_STR_REPEAT),
161161
LintId::of(methods::MAP_COLLECT_RESULT_UNIT),
162+
LintId::of(methods::MAP_FLATTEN),
162163
LintId::of(methods::MAP_IDENTITY),
163164
LintId::of(methods::NEEDLESS_SPLITN),
164165
LintId::of(methods::NEW_RET_NO_SELF),

clippy_lints/src/lib.register_complexity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec!
4141
LintId::of(methods::MANUAL_FILTER_MAP),
4242
LintId::of(methods::MANUAL_FIND_MAP),
4343
LintId::of(methods::MANUAL_SPLIT_ONCE),
44+
LintId::of(methods::MAP_FLATTEN),
4445
LintId::of(methods::MAP_IDENTITY),
4546
LintId::of(methods::NEEDLESS_SPLITN),
4647
LintId::of(methods::OPTION_AS_REF_DEREF),

clippy_lints/src/lib.register_pedantic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
6363
LintId::of(methods::FROM_ITER_INSTEAD_OF_COLLECT),
6464
LintId::of(methods::IMPLICIT_CLONE),
6565
LintId::of(methods::INEFFICIENT_TO_STRING),
66-
LintId::of(methods::MAP_FLATTEN),
6766
LintId::of(methods::MAP_UNWRAP_OR),
6867
LintId::of(misc::FLOAT_CMP),
6968
LintId::of(misc::USED_UNDERSCORE_BINDING),

clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ declare_clippy_lint! {
543543
/// ```
544544
#[clippy::version = "1.31.0"]
545545
pub MAP_FLATTEN,
546-
pedantic,
546+
complexity,
547547
"using combinations of `flatten` and `map` which can usually be written as a single method call"
548548
}
549549

tests/ui/option_env_unwrap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// aux-build:macro_rules.rs
22
#![warn(clippy::option_env_unwrap)]
3+
#![allow(clippy::map_flatten)]
34

45
#[macro_use]
56
extern crate macro_rules;

tests/ui/option_env_unwrap.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this will panic at run-time if the environment variable doesn't exist at compile-time
2-
--> $DIR/option_env_unwrap.rs:17:13
2+
--> $DIR/option_env_unwrap.rs:18:13
33
|
44
LL | let _ = option_env!("PATH").unwrap();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,15 +8,15 @@ LL | let _ = option_env!("PATH").unwrap();
88
= help: consider using the `env!` macro instead
99

1010
error: this will panic at run-time if the environment variable doesn't exist at compile-time
11-
--> $DIR/option_env_unwrap.rs:18:13
11+
--> $DIR/option_env_unwrap.rs:19:13
1212
|
1313
LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set");
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
1616
= help: consider using the `env!` macro instead
1717

1818
error: this will panic at run-time if the environment variable doesn't exist at compile-time
19-
--> $DIR/option_env_unwrap.rs:9:9
19+
--> $DIR/option_env_unwrap.rs:10:9
2020
|
2121
LL | option_env!($env).unwrap()
2222
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -28,7 +28,7 @@ LL | let _ = option_env_unwrap!("PATH");
2828
= note: this error originates in the macro `option_env_unwrap` (in Nightly builds, run with -Z macro-backtrace for more info)
2929

3030
error: this will panic at run-time if the environment variable doesn't exist at compile-time
31-
--> $DIR/option_env_unwrap.rs:12:9
31+
--> $DIR/option_env_unwrap.rs:13:9
3232
|
3333
LL | option_env!($env).expect($message)
3434
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +40,7 @@ LL | let _ = option_env_unwrap!("PATH", "environment variable PATH isn't set
4040
= note: this error originates in the macro `option_env_unwrap` (in Nightly builds, run with -Z macro-backtrace for more info)
4141

4242
error: this will panic at run-time if the environment variable doesn't exist at compile-time
43-
--> $DIR/option_env_unwrap.rs:21:13
43+
--> $DIR/option_env_unwrap.rs:22:13
4444
|
4545
LL | let _ = option_env_unwrap_external!("PATH");
4646
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -49,7 +49,7 @@ LL | let _ = option_env_unwrap_external!("PATH");
4949
= note: this error originates in the macro `option_env_unwrap_external` (in Nightly builds, run with -Z macro-backtrace for more info)
5050

5151
error: this will panic at run-time if the environment variable doesn't exist at compile-time
52-
--> $DIR/option_env_unwrap.rs:22:13
52+
--> $DIR/option_env_unwrap.rs:23:13
5353
|
5454
LL | let _ = option_env_unwrap_external!("PATH", "environment variable PATH isn't set");
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/option_filter_map.fixed

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#![warn(clippy::option_filter_map)]
21
// run-rustfix
3-
fn odds_out(x: i32) -> Option<i32> {
4-
if x % 2 == 0 { Some(x) } else { None }
5-
}
2+
#![warn(clippy::option_filter_map)]
3+
#![allow(clippy::map_flatten)]
64

75
fn main() {
86
let _ = Some(Some(1)).flatten();
@@ -21,3 +19,7 @@ fn main() {
2119
.map(odds_out)
2220
.flatten();
2321
}
22+
23+
fn odds_out(x: i32) -> Option<i32> {
24+
if x % 2 == 0 { Some(x) } else { None }
25+
}

tests/ui/option_filter_map.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#![warn(clippy::option_filter_map)]
21
// run-rustfix
3-
fn odds_out(x: i32) -> Option<i32> {
4-
if x % 2 == 0 { Some(x) } else { None }
5-
}
2+
#![warn(clippy::option_filter_map)]
3+
#![allow(clippy::map_flatten)]
64

75
fn main() {
86
let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap);
@@ -23,3 +21,7 @@ fn main() {
2321
.filter(|o| o.is_some())
2422
.map(|o| o.unwrap());
2523
}
24+
25+
fn odds_out(x: i32) -> Option<i32> {
26+
if x % 2 == 0 { Some(x) } else { None }
27+
}

tests/ui/option_filter_map.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
error: `filter` for `Some` followed by `unwrap`
2-
--> $DIR/option_filter_map.rs:8:27
2+
--> $DIR/option_filter_map.rs:6:27
33
|
44
LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()`
66
|
77
= note: `-D clippy::option-filter-map` implied by `-D warnings`
88

99
error: `filter` for `Some` followed by `unwrap`
10-
--> $DIR/option_filter_map.rs:9:27
10+
--> $DIR/option_filter_map.rs:7:27
1111
|
1212
LL | let _ = Some(Some(1)).filter(|o| o.is_some()).map(|o| o.unwrap());
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()`
1414

1515
error: `filter` for `Some` followed by `unwrap`
16-
--> $DIR/option_filter_map.rs:10:35
16+
--> $DIR/option_filter_map.rs:8:35
1717
|
1818
LL | let _ = Some(1).map(odds_out).filter(Option::is_some).map(Option::unwrap);
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()`
2020

2121
error: `filter` for `Some` followed by `unwrap`
22-
--> $DIR/option_filter_map.rs:11:35
22+
--> $DIR/option_filter_map.rs:9:35
2323
|
2424
LL | let _ = Some(1).map(odds_out).filter(|o| o.is_some()).map(|o| o.unwrap());
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()`
2626

2727
error: `filter` for `Some` followed by `unwrap`
28-
--> $DIR/option_filter_map.rs:13:39
28+
--> $DIR/option_filter_map.rs:11:39
2929
|
3030
LL | let _ = vec![Some(1)].into_iter().filter(Option::is_some).map(Option::unwrap);
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()`
3232

3333
error: `filter` for `Some` followed by `unwrap`
34-
--> $DIR/option_filter_map.rs:14:39
34+
--> $DIR/option_filter_map.rs:12:39
3535
|
3636
LL | let _ = vec![Some(1)].into_iter().filter(|o| o.is_some()).map(|o| o.unwrap());
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()`
3838

3939
error: `filter` for `Some` followed by `unwrap`
40-
--> $DIR/option_filter_map.rs:18:10
40+
--> $DIR/option_filter_map.rs:16:10
4141
|
4242
LL | .filter(Option::is_some)
4343
| __________^
4444
LL | | .map(Option::unwrap);
4545
| |____________________________^ help: consider using `flatten` instead: `flatten()`
4646

4747
error: `filter` for `Some` followed by `unwrap`
48-
--> $DIR/option_filter_map.rs:23:10
48+
--> $DIR/option_filter_map.rs:21:10
4949
|
5050
LL | .filter(|o| o.is_some())
5151
| __________^

0 commit comments

Comments
 (0)