Skip to content

Commit b36a206

Browse files
committed
joined_uncovered_patterns: use slice pats & eta-reduce.
1 parent 5435b38 commit b36a206

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/librustc_mir/hair/pattern/check_match.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,17 +489,16 @@ fn check_exhaustive<'tcx>(
489489

490490
fn joined_uncovered_patterns(witnesses: &[&Pattern<'_>]) -> String {
491491
const LIMIT: usize = 3;
492-
match witnesses.len() {
493-
0 => bug!(),
494-
1 => format!("`{}`", witnesses[0]),
495-
2..=LIMIT => {
496-
let (tail, head) = witnesses.split_last().unwrap();
497-
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
492+
match witnesses {
493+
[] => bug!(),
494+
[witness] => format!("`{}`", witness),
495+
[head @ .., tail] if head.len() < LIMIT => {
496+
let head: Vec<_> = head.iter().map(<_>::to_string).collect();
498497
format!("`{}` and `{}`", head.join("`, `"), tail)
499498
}
500499
_ => {
501500
let (head, tail) = witnesses.split_at(LIMIT);
502-
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
501+
let head: Vec<_> = head.iter().map(<_>::to_string).collect();
503502
format!("`{}` and {} more", head.join("`, `"), tail.len())
504503
}
505504
}

0 commit comments

Comments
 (0)