Skip to content

Commit

Permalink
Auto merge of rust-lang#11756 - y21:issue11755, r=Manishearth
Browse files Browse the repository at this point in the history
[`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
  • Loading branch information
bors committed Nov 3, 2023
2 parents 902c79c + 294df80 commit 789bc73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/loops/unused_enumerate_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_middle::ty;

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

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

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

if !pat_is_wild(cx, &tuple[0].kind, body) {
if !pat_is_wild(cx, &index.kind, body) {
return;
}

Expand Down Expand Up @@ -53,7 +53,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx
diag,
"remove the `.enumerate()` call",
vec![
(pat.span, snippet(cx, tuple[1].span, "..").into_owned()),
(pat.span, snippet(cx, elem.span, "..").into_owned()),
(arg.span, base_iter.to_string()),
],
);
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/crashes/ice-11755.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![warn(clippy::unused_enumerate_index)]

fn main() {
for () in [()].iter() {}
}

0 comments on commit 789bc73

Please sign in to comment.