mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-21 04:54:26 +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 {
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user