Skip to content

Commit 1425ae1

Browse files
committed
Tweak diagnostics code
1 parent 2079ae3 commit 1425ae1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/librustc_mir/hair/pattern/_match.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -969,19 +969,21 @@ impl<'tcx> Constructor<'tcx> {
969969
}
970970
VarLen(prefix, _) => {
971971
let mut prefix: Vec<_> = subpatterns.by_ref().take(prefix as usize).collect();
972-
let mut suffix: Vec<_> = subpatterns.collect();
973972
if slice.array_len.is_some() {
974973
// Improves diagnostics a bit: if the type is a known-size array, instead
975974
// of reporting `[x, _, .., _, y]`, we prefer to report `[x, .., y]`.
976975
// This is incorrect if the size is not known, since `[_, ..]` captures
977976
// arrays of lengths `>= 1` whereas `[..]` captures any length.
978-
while !suffix.is_empty() && suffix.first().unwrap().is_wildcard() {
979-
suffix.remove(0);
980-
}
981977
while !prefix.is_empty() && prefix.last().unwrap().is_wildcard() {
982978
prefix.pop();
983979
}
984980
}
981+
let suffix: Vec<_> = if slice.array_len.is_some() {
982+
// Same as above.
983+
subpatterns.skip_while(Pat::is_wildcard).collect()
984+
} else {
985+
subpatterns.collect()
986+
};
985987
let wild = Pat::wildcard_from_ty(ty);
986988
PatKind::Slice { prefix, slice: Some(wild), suffix }
987989
}

0 commit comments

Comments
 (0)