1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![warn(clippy::for_loop_over_option, clippy::for_loop_over_result)]
12 /// Tests for_loop_over_result and for_loop_over_option
14 fn for_loop_over_option_and_result() {
16 let result = option.ok_or("x not found");
17 let v = vec![0, 1, 2];
19 // check FOR_LOOP_OVER_OPTION lint
24 // check FOR_LOOP_OVER_RESULT lint
29 for x in option.ok_or("x not found") {
33 // make sure LOOP_OVER_NEXT lint takes clippy::precedence when next() is the last call
35 for x in v.iter().next() {
39 // make sure we lint when next() is not the last call in the chain
40 for x in v.iter().next().and(Some(0)) {
44 for x in v.iter().next().ok_or("x not found") {
48 // check for false positives
50 // for loop false positive
55 // while let false positive for Option
56 while let Some(x) = option {
61 // while let false positive for Result
62 while let Ok(x) = result {