Skip to content

Commit

Permalink
joined_uncovered_patterns: use slice pats & eta-reduce.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Sep 9, 2019
1 parent 5435b38 commit b36a206
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/librustc_mir/hair/pattern/check_match.rs
Expand Up @@ -489,17 +489,16 @@ fn check_exhaustive<'tcx>(

fn joined_uncovered_patterns(witnesses: &[&Pattern<'_>]) -> String {
const LIMIT: usize = 3;
match witnesses.len() {
0 => bug!(),
1 => format!("`{}`", witnesses[0]),
2..=LIMIT => {
let (tail, head) = witnesses.split_last().unwrap();
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
match witnesses {
[] => bug!(),
[witness] => format!("`{}`", witness),
[head @ .., tail] if head.len() < LIMIT => {
let head: Vec<_> = head.iter().map(<_>::to_string).collect();
format!("`{}` and `{}`", head.join("`, `"), tail)
}
_ => {
let (head, tail) = witnesses.split_at(LIMIT);
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
let head: Vec<_> = head.iter().map(<_>::to_string).collect();
format!("`{}` and {} more", head.join("`, `"), tail.len())
}
}
Expand Down

0 comments on commit b36a206

Please sign in to comment.