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