]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/unnecessary_find_map.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / unnecessary_find_map.rs
1 #![allow(dead_code)]
2
3 fn main() {
4 let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None });
5 //~^ ERROR: this `.find_map` can be written more simply using `.find`
6 //~| NOTE: `-D clippy::unnecessary-find-map` implied by `-D warnings`
7 let _ = (0..4).find_map(|x| {
8 //~^ ERROR: this `.find_map` can be written more simply using `.find`
9 if x > 1 {
10 return Some(x);
11 };
12 None
13 });
14 let _ = (0..4).find_map(|x| match x {
15 //~^ ERROR: this `.find_map` can be written more simply using `.find`
16 0 | 1 => None,
17 _ => Some(x),
18 });
19
20 let _ = (0..4).find_map(|x| Some(x + 1));
21 //~^ ERROR: this `.find_map` can be written more simply using `.map(..).next()`
22
23 let _ = (0..4).find_map(i32::checked_abs);
24 }
25
26 fn find_map_none_changes_item_type() -> Option<bool> {
27 "".chars().find_map(|_| None)
28 }
29
30 fn issue11260() {
31 let y = Some(1);
32 let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n));
33 let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(y)); // different option, so can't be just `.find()`
34 }