2021-01-14 22:36:36 +00:00
|
|
|
// 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!()
|
|
|
|
}
|
2022-06-01 15:57:08 +00:00
|
|
|
|
2022-06-04 12:20:41 +00:00
|
|
|
struct Issue8920<'a> {
|
|
|
|
option_field: Option<String>,
|
|
|
|
result_field: Result<String, ()>,
|
|
|
|
ref_field: Option<&'a usize>,
|
2022-06-01 15:57:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_8920() {
|
2022-06-04 12:20:41 +00:00
|
|
|
let mut vec = vec![Issue8920 {
|
|
|
|
option_field: Some(String::from("str")),
|
|
|
|
result_field: Ok(String::from("str")),
|
|
|
|
ref_field: Some(&1),
|
2022-06-01 15:57:08 +00:00
|
|
|
}];
|
|
|
|
|
2022-06-04 12:20:41 +00:00
|
|
|
let _ = vec
|
|
|
|
.iter()
|
|
|
|
.find_map(|f| f.option_field.clone());
|
|
|
|
|
|
|
|
let _ = vec
|
|
|
|
.iter()
|
|
|
|
.find_map(|f| f.ref_field.cloned());
|
2022-06-04 07:55:33 +00:00
|
|
|
|
2022-06-04 12:20:41 +00:00
|
|
|
let _ = vec
|
|
|
|
.iter()
|
|
|
|
.find_map(|f| f.ref_field.copied());
|
|
|
|
|
|
|
|
let _ = vec
|
|
|
|
.iter()
|
|
|
|
.find_map(|f| f.result_field.clone().ok());
|
|
|
|
|
|
|
|
let _ = vec
|
|
|
|
.iter()
|
|
|
|
.find_map(|f| f.result_field.as_ref().ok());
|
2022-06-04 07:55:33 +00:00
|
|
|
|
|
|
|
let _ = vec
|
|
|
|
.iter()
|
2022-06-04 12:20:41 +00:00
|
|
|
.find_map(|f| f.result_field.as_deref().ok());
|
2022-06-04 07:55:33 +00:00
|
|
|
|
|
|
|
let _ = vec
|
|
|
|
.iter_mut()
|
2022-06-04 12:20:41 +00:00
|
|
|
.find_map(|f| f.result_field.as_mut().ok());
|
2022-06-04 07:55:33 +00:00
|
|
|
|
|
|
|
let _ = vec
|
|
|
|
.iter_mut()
|
2022-06-04 12:20:41 +00:00
|
|
|
.find_map(|f| f.result_field.as_deref_mut().ok());
|
2022-06-04 07:55:33 +00:00
|
|
|
|
|
|
|
let _ = vec
|
|
|
|
.iter()
|
2022-06-04 12:20:41 +00:00
|
|
|
.find_map(|f| f.result_field.to_owned().ok());
|
2022-06-01 15:57:08 +00:00
|
|
|
}
|