1 #![warn(clippy::for_loop_over_option, clippy::for_loop_over_result)]
3 /// Tests for_loop_over_result and for_loop_over_option
5 fn for_loop_over_option_and_result() {
7 let result = option.ok_or("x not found");
10 // check FOR_LOOP_OVER_OPTION lint
15 // check FOR_LOOP_OVER_RESULT lint
20 for x in option.ok_or("x not found") {
24 // make sure LOOP_OVER_NEXT lint takes clippy::precedence when next() is the last call
26 for x in v.iter().next() {
30 // make sure we lint when next() is not the last call in the chain
31 for x in v.iter().next().and(Some(0)) {
35 for x in v.iter().next().ok_or("x not found") {
39 // check for false positives
41 // for loop false positive
46 // while let false positive for Option
47 while let Some(x) = option {
52 // while let false positive for Result
53 while let Ok(x) = result {