Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Tweak diagnostics code
  • Loading branch information
Nadrieril committed Nov 18, 2019
1 parent 2079ae3 commit 1425ae1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/librustc_mir/hair/pattern/_match.rs
Expand Up @@ -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 }
}
Expand Down

0 comments on commit 1425ae1

Please sign in to comment.