]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/option_map_or_none.fixed
Auto merge of #97944 - nikic:freebsd-update, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / option_map_or_none.fixed
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(|x| x + 1);
13     // Multi-line case.
14     #[rustfmt::skip]
15     let _: Option<i32> = opt.map(|x| x + 1);
16     // function returning `Option`
17     let _: Option<i32> = opt.and_then(bar);
18     let _: Option<i32> = opt.and_then(|x| {
19         let offset = 0;
20         let height = x;
21         Some(offset + height)
22     });
23
24     // Check `RESULT_MAP_OR_INTO_OPTION`.
25     let _: Option<i32> = r.ok();
26 }