Skip to content

Commit f94aeaf

Browse files
committed
Remove check for manual_is_variant_and in map_unwrap_or
1 parent 1e5d605 commit f94aeaf

File tree

5 files changed

+33
-44
lines changed

5 files changed

+33
-44
lines changed

clippy_lints/src/methods/map_unwrap_or.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ pub(super) fn check<'tcx>(
7777
return;
7878
}
7979

80-
// is_some_and is stabilised && `unwrap_or` argument is false; suggest `is_some_and` instead
81-
let suggest_is_some_and = matches!(&unwrap_arg.kind, ExprKind::Lit(lit)
82-
if matches!(lit.node, rustc_ast::LitKind::Bool(false)))
83-
&& msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND);
84-
8580
let mut applicability = Applicability::MachineApplicable;
8681
// get snippet for unwrap_or()
8782
let unwrap_snippet = snippet_with_applicability(cx, unwrap_arg.span, "..", &mut applicability);
@@ -93,21 +88,9 @@ pub(super) fn check<'tcx>(
9388
.basic_res()
9489
.ctor_parent(cx)
9590
.is_lang_item(cx, LangItem::OptionNone);
96-
let arg = if unwrap_snippet_none {
97-
"None"
98-
} else if suggest_is_some_and {
99-
"false"
100-
} else {
101-
"<a>"
102-
};
91+
let arg = if unwrap_snippet_none { "None" } else { "<a>" };
10392
let suggest = if unwrap_snippet_none {
10493
"and_then(<f>)"
105-
} else if suggest_is_some_and {
106-
if is_option {
107-
"is_some_and(<f>)"
108-
} else {
109-
"is_ok_and(<f>)"
110-
}
11194
} else {
11295
"map_or(<a>, <f>)"
11396
};
@@ -124,8 +107,6 @@ pub(super) fn check<'tcx>(
124107
map_span,
125108
String::from(if unwrap_snippet_none {
126109
"and_then"
127-
} else if suggest_is_some_and {
128-
if is_option { "is_some_and" } else { "is_ok_and" }
129110
} else {
130111
let unwrap_arg_ty = unwrap_arg_ty.peel_refs();
131112
if unwrap_arg_ty.is_array()
@@ -140,7 +121,7 @@ pub(super) fn check<'tcx>(
140121
(expr.span.with_lo(unwrap_recv.span.hi()), String::new()),
141122
];
142123

143-
if !unwrap_snippet_none && !suggest_is_some_and {
124+
if !unwrap_snippet_none {
144125
suggestion.push((map_arg_span.with_hi(map_arg_span.lo()), format!("{unwrap_snippet}, ")));
145126
}
146127

tests/ui/map_unwrap_or.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ LL | | 0
135135
LL | | );
136136
| |_________^
137137

138-
error: called `map(<f>).unwrap_or(false)` on an `Option` value
138+
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value
139139
--> tests/ui/map_unwrap_or.rs:70:13
140140
|
141141
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
142142
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143143
|
144-
help: use `is_some_and(<f>)` instead
144+
help: use `map_or(<a>, <f>)` instead
145145
|
146146
LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
147-
LL + let _ = opt.is_some_and(|x| x > 5);
147+
LL + let _ = opt.map_or(false, |x| x > 5);
148148
|
149149

150150
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value
@@ -187,16 +187,16 @@ LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
187187
LL + let _ = opt.map_or(false, |x| x > 5);
188188
|
189189

190-
error: called `map(<f>).unwrap_or(false)` on an `Option` value
190+
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value
191191
--> tests/ui/map_unwrap_or.rs:127:13
192192
|
193193
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
194194
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
195195
|
196-
help: use `is_some_and(<f>)` instead
196+
help: use `map_or(<a>, <f>)` instead
197197
|
198198
LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
199-
LL + let _ = opt.is_some_and(|x| x > 5);
199+
LL + let _ = opt.map_or(false, |x| x > 5);
200200
|
201201

202202
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value

tests/ui/map_unwrap_or_fixable.fixed

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//@aux-build:option_helpers.rs
22

33
#![warn(clippy::map_unwrap_or)]
4-
#![allow(clippy::unnecessary_lazy_evaluations)]
4+
#![allow(
5+
clippy::unnecessary_lazy_evaluations,
6+
clippy::manual_is_variant_and,
7+
clippy::unnecessary_map_or
8+
)]
59

610
#[macro_use]
711
extern crate option_helpers;
@@ -65,7 +69,7 @@ fn issue15714() {
6569
println!("{}", r.map_or_else(|()| 3, |y| y + 1));
6670
//~^ map_unwrap_or
6771

68-
println!("{}", r.is_ok_and(|y| y == 1));
72+
println!("{}", r.map_or(false, |y| y == 1));
6973
//~^ map_unwrap_or
7074
}
7175

tests/ui/map_unwrap_or_fixable.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//@aux-build:option_helpers.rs
22

33
#![warn(clippy::map_unwrap_or)]
4-
#![allow(clippy::unnecessary_lazy_evaluations)]
4+
#![allow(
5+
clippy::unnecessary_lazy_evaluations,
6+
clippy::manual_is_variant_and,
7+
clippy::unnecessary_map_or
8+
)]
59

610
#[macro_use]
711
extern crate option_helpers;

tests/ui/map_unwrap_or_fixable.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value
2-
--> tests/ui/map_unwrap_or_fixable.rs:17:13
2+
--> tests/ui/map_unwrap_or_fixable.rs:21:13
33
|
44
LL | let _ = opt.map(|x| x + 1)
55
| _____________^
@@ -11,7 +11,7 @@ LL | | .unwrap_or_else(|| 0);
1111
= help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]`
1212

1313
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value
14-
--> tests/ui/map_unwrap_or_fixable.rs:48:13
14+
--> tests/ui/map_unwrap_or_fixable.rs:52:13
1515
|
1616
LL | let _ = res.map(|x| x + 1)
1717
| _____________^
@@ -20,7 +20,7 @@ LL | | .unwrap_or_else(|_e| 0);
2020
| |_______________________________^ help: try: `res.map_or_else(|_e| 0, |x| x + 1)`
2121

2222
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value
23-
--> tests/ui/map_unwrap_or_fixable.rs:65:20
23+
--> tests/ui/map_unwrap_or_fixable.rs:69:20
2424
|
2525
LL | println!("{}", o.map(|y| y + 1).unwrap_or(3));
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -32,13 +32,13 @@ LL + println!("{}", o.map_or(3, |y| y + 1));
3232
|
3333

3434
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value
35-
--> tests/ui/map_unwrap_or_fixable.rs:67:20
35+
--> tests/ui/map_unwrap_or_fixable.rs:71:20
3636
|
3737
LL | println!("{}", o.map(|y| y + 1).unwrap_or_else(|| 3));
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `o.map_or_else(|| 3, |y| y + 1)`
3939

4040
error: called `map(<f>).unwrap_or(<a>)` on an `Result` value
41-
--> tests/ui/map_unwrap_or_fixable.rs:69:20
41+
--> tests/ui/map_unwrap_or_fixable.rs:73:20
4242
|
4343
LL | println!("{}", r.map(|y| y + 1).unwrap_or(3));
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -50,25 +50,25 @@ LL + println!("{}", r.map_or(3, |y| y + 1));
5050
|
5151

5252
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value
53-
--> tests/ui/map_unwrap_or_fixable.rs:71:20
53+
--> tests/ui/map_unwrap_or_fixable.rs:75:20
5454
|
5555
LL | println!("{}", r.map(|y| y + 1).unwrap_or_else(|()| 3));
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r.map_or_else(|()| 3, |y| y + 1)`
5757

58-
error: called `map(<f>).unwrap_or(false)` on an `Result` value
59-
--> tests/ui/map_unwrap_or_fixable.rs:74:20
58+
error: called `map(<f>).unwrap_or(<a>)` on an `Result` value
59+
--> tests/ui/map_unwrap_or_fixable.rs:78:20
6060
|
6161
LL | println!("{}", r.map(|y| y == 1).unwrap_or(false));
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363
|
64-
help: use `is_ok_and(<f>)` instead
64+
help: use `map_or(<a>, <f>)` instead
6565
|
6666
LL - println!("{}", r.map(|y| y == 1).unwrap_or(false));
67-
LL + println!("{}", r.is_ok_and(|y| y == 1));
67+
LL + println!("{}", r.map_or(false, |y| y == 1));
6868
|
6969

7070
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value
71-
--> tests/ui/map_unwrap_or_fixable.rs:80:20
71+
--> tests/ui/map_unwrap_or_fixable.rs:84:20
7272
|
7373
LL | println!("{}", x.map(|y| y + 1).unwrap_or(3));
7474
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -80,7 +80,7 @@ LL + println!("{}", x.map_or(3, |y| y + 1));
8080
|
8181

8282
error: called `map(<f>).unwrap_or(<a>)` on an `Result` value
83-
--> tests/ui/map_unwrap_or_fixable.rs:84:20
83+
--> tests/ui/map_unwrap_or_fixable.rs:88:20
8484
|
8585
LL | println!("{}", x.map(|y| y + 1).unwrap_or(3));
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -92,13 +92,13 @@ LL + println!("{}", x.map_or(3, |y| y + 1));
9292
|
9393

9494
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value
95-
--> tests/ui/map_unwrap_or_fixable.rs:88:20
95+
--> tests/ui/map_unwrap_or_fixable.rs:92:20
9696
|
9797
LL | println!("{}", x.map(|y| y + 1).unwrap_or_else(|| 3));
9898
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.map_or_else(|| 3, |y| y + 1)`
9999

100100
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value
101-
--> tests/ui/map_unwrap_or_fixable.rs:92:20
101+
--> tests/ui/map_unwrap_or_fixable.rs:96:20
102102
|
103103
LL | println!("{}", x.map(|y| y + 1).unwrap_or_else(|_| 3));
104104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.map_or_else(|_| 3, |y| y + 1)`

0 commit comments

Comments
 (0)