joined_uncovered_patterns: use slice pats & eta-reduce.

This commit is contained in:
Mazdak Farrokhzad 2019-09-09 02:05:54 +02:00
parent 5435b38456
commit b36a206a30

View File

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