1 #![warn(clippy::manual_flatten)]
2 #![allow(clippy::useless_vec, clippy::uninlined_format_args)]
5 // Test for loop over implicitly adjusted `Iterator` with `if let` expression
6 let x = vec![Some(1), Some(2), Some(3)];
13 // Test for loop over implicitly adjusted `Iterator` with `if let` statement
14 let y: Vec<Result<i32, i32>> = vec![];
21 // Test for loop over by reference
28 // Test for loop over an implicit reference
36 // Test for loop over `Iterator` with `if let` expression
37 let z = vec![Some(1), Some(2), Some(3)];
45 // Using the `None` variant should not trigger the lint
46 // Note: for an autofixable suggestion, the binding in the for loop has to take the
47 // name of the binding in the `if let`
48 let z = vec![Some(1), Some(2), Some(3)];
55 // Using the `Err` variant should not trigger the lint
58 println!("Oops: {}!", e);
62 // Having an else clause should not trigger the lint
71 let vec_of_ref = vec![&Some(1)];
72 for n in &vec_of_ref {
78 let vec_of_ref = &vec_of_ref;
85 let slice_of_ref = &[&Some(1)];
86 for n in slice_of_ref {
96 let mut vec_of_struct = [Some(Test { a: 1 }), None];
98 // Usage of `if let` expression should not trigger lint
99 for n in vec_of_struct.iter_mut() {
105 // Using manual flatten should not trigger the lint
106 for n in vec![Some(1), Some(2), Some(3)].iter().flatten() {
110 run_unformatted_tests();
114 fn run_unformatted_tests() {
115 // Skip rustfmt here on purpose so the suggestion does not fit in one line