1 // aux-build:option_helpers.rs
3 #![warn(clippy::map_unwrap_or)]
6 extern crate option_helpers;
8 use std::collections::HashMap;
14 // Check for `option.map(_).unwrap_or(_)` use.
20 let _ = opt.map(|x| x + 1)
24 // Single line `map(f).unwrap_or(None)` case.
25 let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
26 // Multi-line `map(f).unwrap_or(None)` cases.
35 let _ = opt_map!(opt, |x| x + 1).unwrap_or(0); // should not lint
37 // Should not lint if not copyable
38 let id: String = "identifier".to_string();
39 let _ = Some("prefix").map(|p| format!("{}.{}", p, id)).unwrap_or(id);
40 // ...but DO lint if the `unwrap_or` argument is not used in the `map`
41 let id: String = "identifier".to_string();
42 let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
44 // Check for `option.map(_).unwrap_or_else(_)` use.
49 ).unwrap_or_else(|| 0);
50 let _ = opt.map(|x| x + 1)