]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/bind_instead_of_map.rs
Rollup merge of #102581 - jyn514:src-detection, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / bind_instead_of_map.rs
1 // run-rustfix
2 #![deny(clippy::bind_instead_of_map)]
3 #![allow(clippy::uninlined_format_args)]
4
5 // need a main anyway, use it get rid of unused warnings too
6 pub fn main() {
7     let x = Some(5);
8     // the easiest cases
9     let _ = x.and_then(Some);
10     let _ = x.and_then(|o| Some(o + 1));
11     // and an easy counter-example
12     let _ = x.and_then(|o| if o < 32 { Some(o) } else { None });
13
14     // Different type
15     let x: Result<u32, &str> = Ok(1);
16     let _ = x.and_then(Ok);
17 }
18
19 pub fn foo() -> Option<String> {
20     let x = Some(String::from("hello"));
21     Some("hello".to_owned()).and_then(|s| Some(format!("{}{}", s, x?)))
22 }
23
24 pub fn example2(x: bool) -> Option<&'static str> {
25     Some("a").and_then(|s| Some(if x { s } else { return None }))
26 }