1 // FIXME: Add "run-rustfix" once it's supported for multipart suggestions
2 // aux-build:option_helpers.rs
4 #![warn(clippy::map_unwrap_or)]
7 extern crate option_helpers;
9 use std::collections::HashMap;
15 // Check for `option.map(_).unwrap_or(_)` use.
17 let _ = opt.map(|x| x + 1)
18 // Should lint even though this call is on a separate line.
25 let _ = opt.map(|x| x + 1)
29 // Single line `map(f).unwrap_or(None)` case.
30 let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
31 // Multi-line `map(f).unwrap_or(None)` cases.
40 let _ = opt_map!(opt, |x| x + 1).unwrap_or(0); // should not lint
42 // Should not lint if not copyable
43 let id: String = "identifier".to_string();
44 let _ = Some("prefix").map(|p| format!("{}.{}", p, id)).unwrap_or(id);
45 // ...but DO lint if the `unwrap_or` argument is not used in the `map`
46 let id: String = "identifier".to_string();
47 let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
49 // Check for `option.map(_).unwrap_or_else(_)` use.
51 let _ = opt.map(|x| x + 1)
52 // Should lint even though this call is on a separate line.
53 .unwrap_or_else(|| 0);
58 ).unwrap_or_else(|| 0);
59 let _ = opt.map(|x| x + 1)
65 let _ = opt_map!(opt, |x| x + 1).unwrap_or_else(|| 0);
69 let mut frequencies = HashMap::new();
78 frequencies.insert(word.to_owned(), 1);
84 let res: Result<i32, ()> = Ok(1);
86 // Check for `result.map(_).unwrap_or_else(_)` use.
88 let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0); // should lint even though this call is on a separate line
90 let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0);
91 let _ = res.map(|x| x + 1).unwrap_or_else(|e| 0);
93 let _ = opt_map!(res, |x| x + 1).unwrap_or_else(|e| 0); // should not lint