Skip to content

Commit cfd17d4

Browse files
authored
Use a better message for unnecessary_map_or lint (rust-lang#13708)
Suggested by, and closes rust-lang#13704. changelog: [`unnecessary_map_or`]: use a clearer lint message
2 parents 10677c3 + 425346a commit cfd17d4

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

clippy_lints/src/methods/unnecessary_map_or.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub(super) fn check<'a>(
135135
cx,
136136
UNNECESSARY_MAP_OR,
137137
expr.span,
138-
"this `map_or` is redundant",
138+
"this `map_or` can be simplified",
139139
format!("use {method} instead"),
140140
sugg,
141141
applicability,

tests/ui/unnecessary_map_or.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: this `map_or` is redundant
1+
error: this `map_or` can be simplified
22
--> tests/ui/unnecessary_map_or.rs:12:13
33
|
44
LL | let _ = Some(5).map_or(false, |n| n == 5);
@@ -7,13 +7,13 @@ LL | let _ = Some(5).map_or(false, |n| n == 5);
77
= note: `-D clippy::unnecessary-map-or` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_map_or)]`
99

10-
error: this `map_or` is redundant
10+
error: this `map_or` can be simplified
1111
--> tests/ui/unnecessary_map_or.rs:13:13
1212
|
1313
LL | let _ = Some(5).map_or(true, |n| n != 5);
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(Some(5) != Some(5))`
1515

16-
error: this `map_or` is redundant
16+
error: this `map_or` can be simplified
1717
--> tests/ui/unnecessary_map_or.rs:14:13
1818
|
1919
LL | let _ = Some(5).map_or(false, |n| {
@@ -23,7 +23,7 @@ LL | | n == 5
2323
LL | | });
2424
| |______^ help: use a standard comparison instead: `(Some(5) == Some(5))`
2525

26-
error: this `map_or` is redundant
26+
error: this `map_or` can be simplified
2727
--> tests/ui/unnecessary_map_or.rs:18:13
2828
|
2929
LL | let _ = Some(5).map_or(false, |n| {
@@ -41,85 +41,85 @@ LL + 6 >= 5
4141
LL ~ });
4242
|
4343

44-
error: this `map_or` is redundant
44+
error: this `map_or` can be simplified
4545
--> tests/ui/unnecessary_map_or.rs:22:13
4646
|
4747
LL | let _ = Some(vec![5]).map_or(false, |n| n == [5]);
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_some_and instead: `Some(vec![5]).is_some_and(|n| n == [5])`
4949

50-
error: this `map_or` is redundant
50+
error: this `map_or` can be simplified
5151
--> tests/ui/unnecessary_map_or.rs:23:13
5252
|
5353
LL | let _ = Some(vec![1]).map_or(false, |n| vec![2] == n);
5454
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_some_and instead: `Some(vec![1]).is_some_and(|n| vec![2] == n)`
5555

56-
error: this `map_or` is redundant
56+
error: this `map_or` can be simplified
5757
--> tests/ui/unnecessary_map_or.rs:24:13
5858
|
5959
LL | let _ = Some(5).map_or(false, |n| n == n);
6060
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_some_and instead: `Some(5).is_some_and(|n| n == n)`
6161

62-
error: this `map_or` is redundant
62+
error: this `map_or` can be simplified
6363
--> tests/ui/unnecessary_map_or.rs:25:13
6464
|
6565
LL | let _ = Some(5).map_or(false, |n| n == if 2 > 1 { n } else { 0 });
6666
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_some_and instead: `Some(5).is_some_and(|n| n == if 2 > 1 { n } else { 0 })`
6767

68-
error: this `map_or` is redundant
68+
error: this `map_or` can be simplified
6969
--> tests/ui/unnecessary_map_or.rs:26:13
7070
|
7171
LL | let _ = Ok::<Vec<i32>, i32>(vec![5]).map_or(false, |n| n == [5]);
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_ok_and instead: `Ok::<Vec<i32>, i32>(vec![5]).is_ok_and(|n| n == [5])`
7373

74-
error: this `map_or` is redundant
74+
error: this `map_or` can be simplified
7575
--> tests/ui/unnecessary_map_or.rs:27:13
7676
|
7777
LL | let _ = Ok::<i32, i32>(5).map_or(false, |n| n == 5);
7878
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(Ok::<i32, i32>(5) == Ok(5))`
7979

80-
error: this `map_or` is redundant
80+
error: this `map_or` can be simplified
8181
--> tests/ui/unnecessary_map_or.rs:28:13
8282
|
8383
LL | let _ = Some(5).map_or(false, |n| n == 5).then(|| 1);
8484
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(Some(5) == Some(5))`
8585

86-
error: this `map_or` is redundant
86+
error: this `map_or` can be simplified
8787
--> tests/ui/unnecessary_map_or.rs:29:13
8888
|
8989
LL | let _ = Some(5).map_or(true, |n| n == 5);
9090
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_none_or instead: `Some(5).is_none_or(|n| n == 5)`
9191

92-
error: this `map_or` is redundant
92+
error: this `map_or` can be simplified
9393
--> tests/ui/unnecessary_map_or.rs:30:13
9494
|
9595
LL | let _ = Some(5).map_or(true, |n| 5 == n);
9696
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_none_or instead: `Some(5).is_none_or(|n| 5 == n)`
9797

98-
error: this `map_or` is redundant
98+
error: this `map_or` can be simplified
9999
--> tests/ui/unnecessary_map_or.rs:54:13
100100
|
101101
LL | let _ = r.map_or(false, |x| x == 7);
102102
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_ok_and instead: `r.is_ok_and(|x| x == 7)`
103103

104-
error: this `map_or` is redundant
104+
error: this `map_or` can be simplified
105105
--> tests/ui/unnecessary_map_or.rs:59:13
106106
|
107107
LL | let _ = r.map_or(false, func);
108108
| ^^^^^^^^^^^^^^^^^^^^^ help: use is_ok_and instead: `r.is_ok_and(func)`
109109

110-
error: this `map_or` is redundant
110+
error: this `map_or` can be simplified
111111
--> tests/ui/unnecessary_map_or.rs:60:13
112112
|
113113
LL | let _ = Some(5).map_or(false, func);
114114
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_some_and instead: `Some(5).is_some_and(func)`
115115

116-
error: this `map_or` is redundant
116+
error: this `map_or` can be simplified
117117
--> tests/ui/unnecessary_map_or.rs:61:13
118118
|
119119
LL | let _ = Some(5).map_or(true, func);
120120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_none_or instead: `Some(5).is_none_or(func)`
121121

122-
error: this `map_or` is redundant
122+
error: this `map_or` can be simplified
123123
--> tests/ui/unnecessary_map_or.rs:66:13
124124
|
125125
LL | let _ = r.map_or(false, |x| x == 8);

0 commit comments

Comments
 (0)