File tree 3 files changed +41
-15
lines changed
3 files changed +41
-15
lines changed Original file line number Diff line number Diff line change @@ -119,10 +119,7 @@ fn issue2965() {
119
119
let mut values = HashSet::new();
120
120
values.insert(1);
121
121
122
- for _ in values.iter() {
123
- // FIXME(flip1995): Linting this with the following line uncommented is a FP, see #1654
124
- // values.remove(&1);
125
- }
122
+ while let Some(..) = values.iter().next() {}
126
123
}
127
124
128
125
fn issue3670() {
@@ -134,11 +131,30 @@ fn issue3670() {
134
131
}
135
132
}
136
133
134
+ fn issue1654() {
135
+ // should not lint if the iterator is generated on every iteration
136
+ use std::collections::HashSet;
137
+ let mut values = HashSet::new();
138
+ values.insert(1);
139
+
140
+ while let Some(..) = values.iter().next() {
141
+ values.remove(&1);
142
+ }
143
+
144
+ while let Some(..) = values.iter().map(|x| x + 1).next() {}
145
+
146
+ let chars = "Hello, World!".char_indices();
147
+ while let Some((i, ch)) = chars.clone().next() {
148
+ println!("{}: {}", i, ch);
149
+ }
150
+ }
151
+
137
152
fn main() {
138
153
base();
139
154
refutable();
140
155
nested_loops();
141
156
issue1121();
142
157
issue2965();
143
158
issue3670();
159
+ issue1654();
144
160
}
Original file line number Diff line number Diff line change @@ -119,10 +119,7 @@ fn issue2965() {
119
119
let mut values = HashSet :: new ( ) ;
120
120
values. insert ( 1 ) ;
121
121
122
- while let Some ( ..) = values. iter ( ) . next ( ) {
123
- // FIXME(flip1995): Linting this with the following line uncommented is a FP, see #1654
124
- // values.remove(&1);
125
- }
122
+ while let Some ( ..) = values. iter ( ) . next ( ) { }
126
123
}
127
124
128
125
fn issue3670 ( ) {
@@ -134,11 +131,30 @@ fn issue3670() {
134
131
}
135
132
}
136
133
134
+ fn issue1654 ( ) {
135
+ // should not lint if the iterator is generated on every iteration
136
+ use std:: collections:: HashSet ;
137
+ let mut values = HashSet :: new ( ) ;
138
+ values. insert ( 1 ) ;
139
+
140
+ while let Some ( ..) = values. iter ( ) . next ( ) {
141
+ values. remove ( & 1 ) ;
142
+ }
143
+
144
+ while let Some ( ..) = values. iter ( ) . map ( |x| x + 1 ) . next ( ) { }
145
+
146
+ let chars = "Hello, World!" . char_indices ( ) ;
147
+ while let Some ( ( i, ch) ) = chars. clone ( ) . next ( ) {
148
+ println ! ( "{}: {}" , i, ch) ;
149
+ }
150
+ }
151
+
137
152
fn main ( ) {
138
153
base ( ) ;
139
154
refutable ( ) ;
140
155
nested_loops ( ) ;
141
156
issue1121 ( ) ;
142
157
issue2965 ( ) ;
143
158
issue3670 ( ) ;
159
+ issue1654 ( ) ;
144
160
}
Original file line number Diff line number Diff line change @@ -24,11 +24,5 @@ error: this loop could be written as a `for` loop
24
24
LL | while let Some(_) = y.next() {
25
25
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in y`
26
26
27
- error: this loop could be written as a `for` loop
28
- --> $DIR/while_let_on_iterator.rs:122:5
29
- |
30
- LL | while let Some(..) = values.iter().next() {
31
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in values.iter()`
32
-
33
- error: aborting due to 5 previous errors
27
+ error: aborting due to 4 previous errors
34
28
You can’t perform that action at this time.
0 commit comments