Skip to content

Commit 6660388

Browse files
borsflip1995
authored andcommitted
Auto merge of rust-lang#11756 - y21:issue11755, r=Manishearth
[`unused_enumerate_index`]: don't ICE on empty tuples Fixes rust-lang#11755 changelog: [`unused_enumerate_index`]: don't ICE on empty tuples I'm going to nominate for beta backport because the code that is needed to trigger this seems likely to occur in real code `@rustbot` label +beta-nominated
1 parent af6a0aa commit 6660388

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty;
99

1010
/// Checks for the `UNUSED_ENUMERATE_INDEX` lint.
1111
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>) {
12-
let PatKind::Tuple(tuple, _) = pat.kind else {
12+
let PatKind::Tuple([index, elem], _) = pat.kind else {
1313
return;
1414
};
1515

@@ -19,7 +19,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx
1919

2020
let ty = cx.typeck_results().expr_ty(arg);
2121

22-
if !pat_is_wild(cx, &tuple[0].kind, body) {
22+
if !pat_is_wild(cx, &index.kind, body) {
2323
return;
2424
}
2525

@@ -53,7 +53,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx
5353
diag,
5454
"remove the `.enumerate()` call",
5555
vec![
56-
(pat.span, snippet(cx, tuple[1].span, "..").into_owned()),
56+
(pat.span, snippet(cx, elem.span, "..").into_owned()),
5757
(arg.span, base_iter.to_string()),
5858
],
5959
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![warn(clippy::unused_enumerate_index)]
2+
3+
fn main() {
4+
for () in [()].iter() {}
5+
}

0 commit comments

Comments
 (0)