mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-18 19:43:43 +00:00
joined_uncovered_patterns: use slice pats & eta-reduce.
This commit is contained in:
parent
5435b38456
commit
b36a206a30
@ -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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user