changed the msrv to 1.70 to suggest is_some_and

if the msrv is not >= 1.70 then the `map_or` is suggested instead of `is_some_and` (even when `unwrap_or` returns false)
This commit is contained in:
darklyspaced 2023-06-26 13:39:45 +08:00
parent 9b7d8d1dc7
commit c60222dc12
No known key found for this signature in database
5 changed files with 49 additions and 6 deletions

View file

@ -99,6 +99,20 @@ fn msrv_1_41() {
let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
}
#[clippy::msrv = "1.69"]
fn msrv_1_69() {
let opt: Option<i32> = Some(1);
let _ = opt.map(|x| x > 5).unwrap_or(false);
}
#[clippy::msrv = "1.70"]
fn msrv_1_70() {
let opt: Option<i32> = Some(1);
let _ = opt.map(|x| x > 5).unwrap_or(false);
}
mod issue_10579 {
// Different variations of the same issue.
fn v1() {

View file

@ -164,5 +164,29 @@ error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be do
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)`
error: aborting due to 13 previous errors
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
--> $DIR/map_unwrap_or.rs:106:13
|
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `map_or(<a>, <f>)` instead
|
LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
LL + let _ = opt.map_or(false, |x| x > 5);
|
error: called `map(<f>).unwrap_or(false)` on an `Option` value. This can be done more directly by calling `is_some_and(<f>)` instead
--> $DIR/map_unwrap_or.rs:113:13
|
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `is_some_and(<f>)` instead
|
LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
LL + let _ = opt.is_some_and(|x| x > 5);
|
error: aborting due to 15 previous errors