Skip to content

Commit 28cd1b8

Browse files
committed
Fix invalid while_let_on_iterator suggestion
Slice patterns without .. are refutable.
1 parent 1620e92 commit 28cd1b8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clippy_lints/src/utils/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,11 @@ pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat) -> bool {
958958
}
959959
},
960960
PatKind::Slice(ref head, ref middle, ref tail) => {
961-
are_refutable(cx, head.iter().chain(middle).chain(tail.iter()).map(|pat| &**pat))
961+
if middle.is_none() {
962+
true
963+
} else {
964+
are_refutable(cx, head.iter().chain(middle).chain(tail.iter()).map(|pat| &**pat))
965+
}
962966
},
963967
}
964968
}

tests/ui/while_loop.rs

+10
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,14 @@ fn refutable() {
226226
let _ = elem.or_else(|| *iter.next()?);
227227
}
228228
}
229+
230+
// Issue 3780
231+
{
232+
let v = vec![1, 2, 3];
233+
let mut it = v.windows(2);
234+
while let Some([x, y]) = it.next() {
235+
println!("x: {}", x);
236+
println!("y: {}", y);
237+
}
238+
}
229239
}

0 commit comments

Comments
 (0)