]> git.lizzy.rs Git - rust.git/blob - tests/ui/option_map_or_none.rs
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / option_map_or_none.rs
1 // run-rustfix
2
3 #![allow(clippy::bind_instead_of_map)]
4
5 fn main() {
6     let opt = Some(1);
7     let r: Result<i32, i32> = Ok(1);
8     let bar = |_| Some(1);
9
10     // Check `OPTION_MAP_OR_NONE`.
11     // Single line case.
12     let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
13     // Multi-line case.
14     #[rustfmt::skip]
15     let _: Option<i32> = opt.map_or(None, |x| {
16                         Some(x + 1)
17                        });
18     // function returning `Option`
19     let _: Option<i32> = opt.map_or(None, bar);
20     let _: Option<i32> = opt.map_or(None, |x| {
21         let offset = 0;
22         let height = x;
23         Some(offset + height)
24     });
25
26     // Check `RESULT_MAP_OR_INTO_OPTION`.
27     let _: Option<i32> = r.map_or(None, Some);
28 }