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