4 #![deny(while_let_loop, empty_loop, while_let_on_iterator)]
5 #![allow(dead_code, unused, cyclomatic_complexity)]
10 //~^ERROR this loop could be written as a `while let` loop
12 //~|SUGGESTION while let Some(_x) = y {
19 loop { // no error, break is not in else clause
26 //~^ERROR this loop could be written as a `while let` loop
28 //~|SUGGESTION while let Some(_x) = y {
35 //~^ERROR this loop could be written as a `while let` loop
37 //~|SUGGESTION while let Some(x) = y {
46 //~^ERROR this loop could be written as a `while let` loop
48 //~|SUGGESTION while let Some(x) = y {
54 { let _b = "foobar"; }
56 loop { // no error, else branch does something other than break
65 while let Some(x) = y { // no error, obviously
69 // #675, this used to have a wrong suggestion
71 //~^ERROR this loop could be written as a `while let` loop
73 //~|SUGGESTION while let Some(word) = "".split_whitespace().next() { .. }
74 let (e, l) = match "".split_whitespace().next() {
75 Some(word) => (word.is_empty(), word.len()),
83 while let Option::Some(x) = iter.next() {
84 //~^ ERROR this loop could be written as a `for` loop
86 //~| SUGGESTION for x in iter {
91 while let Some(x) = iter.next() {
92 //~^ ERROR this loop could be written as a `for` loop
94 //~| SUGGESTION for x in iter {
99 while let Some(_) = iter.next() {}
100 //~^ ERROR this loop could be written as a `for` loop
102 //~| SUGGESTION for _ in iter {
104 let mut iter = 1..20;
105 while let None = iter.next() {} // this is fine (if nonsensical)
107 let mut iter = 1..20;
108 if let Some(x) = iter.next() { // also fine
112 // the following shouldn't warn because it can't be written with a for loop
113 let mut iter = 1u32..20;
114 while let Some(x) = iter.next() {
115 println!("next: {:?}", iter.next())
119 let mut iter = 1u32..20;
120 while let Some(x) = iter.next() {
121 println!("next: {:?}", iter.next());
125 let mut iter = 1u32..20;
126 while let Some(x) = iter.next() {break;}
127 println!("Remaining iter {:?}", iter);
130 let mut iter = 1u32..20;
131 while let Some(x) = iter.next() {
136 // regression test (#360)
137 // this should not panic
138 // it's okay if further iterations of the lint
139 // cause this function to trigger it
140 fn no_panic<T>(slice: &[T]) {
141 let mut iter = slice.iter();
145 //~| SUGGESTION while let Some(ele) = iter.next() { .. }
146 let _ = match iter.next() {
150 loop {} //~ERROR empty `loop {}` detected.
155 let r: Result<u32, u32> = Ok(42);