diff options
| author | y21 <30553356+y21@users.noreply.github.com> | 2023-11-03 21:04:14 +0100 |
|---|---|---|
| committer | y21 <30553356+y21@users.noreply.github.com> | 2023-11-03 21:13:51 +0100 |
| commit | 294df80e2cdfbd16b9e5531b0581f8710b7b8862 (patch) | |
| tree | 45a4f12f47d8774021374812d43412035bf3d92a | |
| parent | 902c79c654b45ab9b8ae425bd2c1fa0c50a3edf7 (diff) | |
| download | rust-294df80e2cdfbd16b9e5531b0581f8710b7b8862.tar.gz rust-294df80e2cdfbd16b9e5531b0581f8710b7b8862.zip | |
[`unused_enumerate_index`]: don't ICE on empty tuples
| -rw-r--r-- | clippy_lints/src/loops/unused_enumerate_index.rs | 6 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-11755.rs | 5 |
2 files changed, 8 insertions, 3 deletions
diff --git a/clippy_lints/src/loops/unused_enumerate_index.rs b/clippy_lints/src/loops/unused_enumerate_index.rs index 62a2ab1ccb4..dd7fae79d9b 100644 --- a/clippy_lints/src/loops/unused_enumerate_index.rs +++ b/clippy_lints/src/loops/unused_enumerate_index.rs @@ -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; }; @@ -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; } @@ -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()), ], ); diff --git a/tests/ui/crashes/ice-11755.rs b/tests/ui/crashes/ice-11755.rs new file mode 100644 index 00000000000..367cb699857 --- /dev/null +++ b/tests/ui/crashes/ice-11755.rs @@ -0,0 +1,5 @@ +#![warn(clippy::unused_enumerate_index)] + +fn main() { + for () in [()].iter() {} +} |
