]> git.lizzy.rs Git - rust.git/blob - tests/ui/manual_ok_or.fixed
Don't suggest let else in match if the else arm explicitly mentions non obvious paths
[rust.git] / tests / ui / manual_ok_or.fixed
1 // run-rustfix
2 #![warn(clippy::manual_ok_or)]
3 #![allow(clippy::or_fun_call)]
4 #![allow(clippy::disallowed_names)]
5 #![allow(clippy::redundant_closure)]
6 #![allow(dead_code)]
7 #![allow(unused_must_use)]
8
9 fn main() {
10     // basic case
11     let foo: Option<i32> = None;
12     foo.ok_or("error");
13
14     // eta expansion case
15     foo.ok_or("error");
16
17     // turbo fish syntax
18     None::<i32>.ok_or("error");
19
20     // multiline case
21     #[rustfmt::skip]
22     foo.ok_or(&format!(
23         "{}{}{}{}{}{}{}",
24         "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer"));
25
26     // not applicable, closure isn't direct `Ok` wrapping
27     foo.map_or(Err("error"), |v| Ok(v + 1));
28
29     // not applicable, or side isn't `Result::Err`
30     foo.map_or(Ok::<i32, &str>(1), |v| Ok(v));
31
32     // not applicable, expr is not a `Result` value
33     foo.map_or(42, |v| v);
34
35     // TODO patterns not covered yet
36     match foo {
37         Some(v) => Ok(v),
38         None => Err("error"),
39     };
40     foo.map_or_else(|| Err("error"), |v| Ok(v));
41 }