about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-27 23:39:41 +0000
committerbors <bors@rust-lang.org>2021-04-27 23:39:41 +0000
commitce37099bd3cc05568c09fa7c1f06c80efd64c905 (patch)
treec026a1cef7164b610a60a185c69def9ed72abba9
parent7c7683c8efe447b251d6c5ca6cce51233060f6e8 (diff)
parent572c405da063d2628378b74a8f659ce90e0e7779 (diff)
downloadrust-ce37099bd3cc05568c09fa7c1f06c80efd64c905.tar.gz
rust-ce37099bd3cc05568c09fa7c1f06c80efd64c905.zip
Auto merge of #7140 - matthiaskrgr:ice_std, r=llogiq
fix ice when checking rustc libstd

```
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', src/tools/clippy/clippy_lints/src/matches.rs:1595:53
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

I don't have a minimised testcase because I don't have time to reduce libstd down to a few lines right now.

---
changelog: fix index out of bounds access when checking rustc libstd
-rw-r--r--clippy_lints/src/matches.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs
index 13b2a834b0a..c7a25095bf6 100644
--- a/clippy_lints/src/matches.rs
+++ b/clippy_lints/src/matches.rs
@@ -1590,9 +1590,9 @@ fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
 // Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`)
 fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<BindingAnnotation> {
     if_chain! {
-        if let PatKind::TupleStruct(ref qpath, pats, _) = arm.pat.kind;
+        if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind;
         if is_lang_ctor(cx, qpath, OptionSome);
-        if let PatKind::Binding(rb, .., ident, _) = pats[0].kind;
+        if let PatKind::Binding(rb, .., ident, _) = first_pat.kind;
         if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut;
         if let ExprKind::Call(e, args) = remove_blocks(arm.body).kind;
         if let ExprKind::Path(ref some_path) = e.kind;