1 // FIXME: Add "run-rustfix" once it's supported for multipart suggestions
2 // aux-build:option_helpers.rs
4 #![warn(clippy::option_map_unwrap_or, clippy::option_map_unwrap_or_else)]
7 extern crate option_helpers;
9 use std::collections::HashMap;
11 /// Checks implementation of the following lints:
12 /// * `OPTION_MAP_UNWRAP_OR`
13 /// * `OPTION_MAP_UNWRAP_OR_ELSE`
18 // Check `OPTION_MAP_UNWRAP_OR`.
20 let _ = opt.map(|x| x + 1)
21 // Should lint even though this call is on a separate line.
28 let _ = opt.map(|x| x + 1)
32 // Single line `map(f).unwrap_or(None)` case.
33 let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
34 // Multi-line `map(f).unwrap_or(None)` cases.
43 let _ = opt_map!(opt, |x| x + 1).unwrap_or(0); // should not lint
45 // Should not lint if not copyable
46 let id: String = "identifier".to_string();
47 let _ = Some("prefix").map(|p| format!("{}.{}", p, id)).unwrap_or(id);
48 // ...but DO lint if the `unwrap_or` argument is not used in the `map`
49 let id: String = "identifier".to_string();
50 let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
52 // Check OPTION_MAP_UNWRAP_OR_ELSE
54 let _ = opt.map(|x| x + 1)
55 // Should lint even though this call is on a separate line.
56 .unwrap_or_else(|| 0);
61 ).unwrap_or_else(|| 0);
62 let _ = opt.map(|x| x + 1)
68 let _ = opt_map!(opt, |x| x + 1).unwrap_or_else(|| 0);
72 let mut frequencies = HashMap::new();
81 frequencies.insert(word.to_owned(), 1);