mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 09:27:25 +00:00
38 lines
965 B
Rust
38 lines
965 B
Rust
|
// run-rustfix
|
||
|
#![allow(dead_code)]
|
||
|
#![warn(clippy::manual_find_map)]
|
||
|
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
|
||
|
|
||
|
fn main() {
|
||
|
// is_some(), unwrap()
|
||
|
let _ = (0..).find_map(|a| to_opt(a));
|
||
|
|
||
|
// ref pattern, expect()
|
||
|
let _ = (0..).find_map(|a| to_opt(a));
|
||
|
|
||
|
// is_ok(), unwrap_or()
|
||
|
let _ = (0..).find_map(|a| to_res(a).ok());
|
||
|
}
|
||
|
|
||
|
fn no_lint() {
|
||
|
// no shared code
|
||
|
let _ = (0..).filter(|n| *n > 1).map(|n| n + 1);
|
||
|
|
||
|
// very close but different since filter() provides a reference
|
||
|
let _ = (0..).find(|n| to_opt(n).is_some()).map(|a| to_opt(a).unwrap());
|
||
|
|
||
|
// similar but different
|
||
|
let _ = (0..).find(|n| to_opt(n).is_some()).map(|n| to_res(n).unwrap());
|
||
|
let _ = (0..)
|
||
|
.find(|n| to_opt(n).map(|n| n + 1).is_some())
|
||
|
.map(|a| to_opt(a).unwrap());
|
||
|
}
|
||
|
|
||
|
fn to_opt<T>(_: T) -> Option<T> {
|
||
|
unimplemented!()
|
||
|
}
|
||
|
|
||
|
fn to_res<T>(_: T) -> Result<T, ()> {
|
||
|
unimplemented!()
|
||
|
}
|