]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/match_result_ok.fixed
Merge commit 'ac0e10aa68325235069a842f47499852b2dee79e' into clippyup
[rust.git] / src / tools / clippy / tests / ui / match_result_ok.fixed
1 // run-rustfix
2 #![warn(clippy::match_result_ok)]
3 #![allow(dead_code)]
4 #![allow(clippy::boxed_local, clippy::uninlined_format_args)]
5
6 // Checking `if` cases
7
8 fn str_to_int(x: &str) -> i32 {
9     if let Ok(y) = x.parse() { y } else { 0 }
10 }
11
12 fn str_to_int_ok(x: &str) -> i32 {
13     if let Ok(y) = x.parse() { y } else { 0 }
14 }
15
16 #[rustfmt::skip]
17 fn strange_some_no_else(x: &str) -> i32 {
18     {
19         if let Ok(y) = x   .   parse()       {
20             return y;
21         };
22         0
23     }
24 }
25
26 // Checking `while` cases
27
28 struct Wat {
29     counter: i32,
30 }
31
32 impl Wat {
33     fn next(&mut self) -> Result<i32, &str> {
34         self.counter += 1;
35         if self.counter < 5 {
36             Ok(self.counter)
37         } else {
38             Err("Oh no")
39         }
40     }
41 }
42
43 fn base_1(x: i32) {
44     let mut wat = Wat { counter: x };
45     while let Ok(a) = wat.next() {
46         println!("{}", a);
47     }
48 }
49
50 fn base_2(x: i32) {
51     let mut wat = Wat { counter: x };
52     while let Ok(a) = wat.next() {
53         println!("{}", a);
54     }
55 }
56
57 fn base_3(test_func: Box<Result<i32, &str>>) {
58     // Expected to stay as is
59     while let Some(_b) = test_func.ok() {}
60 }
61
62 fn main() {}