diff options
| -rw-r--r-- | src/librustc_mir/hair/pattern/_match.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index a6afea22881..5e7a7f01e7a 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -969,19 +969,21 @@ impl<'tcx> Constructor<'tcx> { } VarLen(prefix, _) => { let mut prefix: Vec<_> = subpatterns.by_ref().take(prefix as usize).collect(); - let mut suffix: Vec<_> = subpatterns.collect(); if slice.array_len.is_some() { // Improves diagnostics a bit: if the type is a known-size array, instead // of reporting `[x, _, .., _, y]`, we prefer to report `[x, .., y]`. // This is incorrect if the size is not known, since `[_, ..]` captures // arrays of lengths `>= 1` whereas `[..]` captures any length. - while !suffix.is_empty() && suffix.first().unwrap().is_wildcard() { - suffix.remove(0); - } while !prefix.is_empty() && prefix.last().unwrap().is_wildcard() { prefix.pop(); } } + let suffix: Vec<_> = if slice.array_len.is_some() { + // Same as above. + subpatterns.skip_while(Pat::is_wildcard).collect() + } else { + subpatterns.collect() + }; let wild = Pat::wildcard_from_ty(ty); PatKind::Slice { prefix, slice: Some(wild), suffix } } |
