]> git.lizzy.rs Git - rust.git/blob - tests/ui/lint/for_loop_over_fallibles.rs
Auto merge of #106884 - clubby789:fieldless-enum-debug, r=michaelwoerister
[rust.git] / tests / ui / lint / for_loop_over_fallibles.rs
1 // check-pass
2
3 fn main() {
4     // Common
5     for _ in Some(1) {}
6     //~^ WARN for loop over an `Option`. This is more readably written as an `if let` statement
7     //~| HELP to check pattern in a loop use `while let`
8     //~| HELP consider using `if let` to clear intent
9     for _ in Ok::<_, ()>(1) {}
10     //~^ WARN for loop over a `Result`. This is more readably written as an `if let` statement
11     //~| HELP to check pattern in a loop use `while let`
12     //~| HELP consider using `if let` to clear intent
13
14     // `Iterator::next` specific
15     for _ in [0; 0].iter().next() {}
16     //~^ WARN for loop over an `Option`. This is more readably written as an `if let` statement
17     //~| HELP to iterate over `[0; 0].iter()` remove the call to `next`
18     //~| HELP consider using `if let` to clear intent
19
20     // `Result<impl Iterator, _>`, but function doesn't return `Result`
21     for _ in Ok::<_, ()>([0; 0].iter()) {}
22     //~^ WARN for loop over a `Result`. This is more readably written as an `if let` statement
23     //~| HELP to check pattern in a loop use `while let`
24     //~| HELP consider using `if let` to clear intent
25 }
26
27 fn _returns_result() -> Result<(), ()> {
28     // `Result<impl Iterator, _>`
29     for _ in Ok::<_, ()>([0; 0].iter()) {}
30     //~^ WARN for loop over a `Result`. This is more readably written as an `if let` statement
31     //~| HELP to check pattern in a loop use `while let`
32     //~| HELP consider unwrapping the `Result` with `?` to iterate over its contents
33     //~| HELP consider using `if let` to clear intent
34
35     // `Result<impl IntoIterator>`
36     for _ in Ok::<_, ()>([0; 0]) {}
37     //~^ WARN for loop over a `Result`. This is more readably written as an `if let` statement
38     //~| HELP to check pattern in a loop use `while let`
39     //~| HELP consider unwrapping the `Result` with `?` to iterate over its contents
40     //~| HELP consider using `if let` to clear intent
41
42     Ok(())
43 }