fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

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