Reuse pat_constructor in split_grouped_ctors

This commit is contained in:
Nadrieril 2019-11-17 23:36:29 +00:00
parent e6e5513894
commit 3f917120a0

View File

@ -2096,32 +2096,19 @@ fn split_grouped_constructors<'p, 'tcx>(
let mut max_suffix_len = self_suffix; let mut max_suffix_len = self_suffix;
let mut max_fixed_len = 0; let mut max_fixed_len = 0;
for row in matrix.heads() { let head_ctors =
match *row.kind { matrix.heads().filter_map(|pat| pat_constructor(tcx, param_env, pat));
PatKind::Constant { value } => { for ctor in head_ctors {
// extract the length of an array/slice from a constant match ctor {
match (value.val, &value.ty.kind) { Slice(slice) => match slice.pattern_kind() {
(_, ty::Array(_, n)) => { FixedLen(len) => {
max_fixed_len = max_fixed_len = cmp::max(max_fixed_len, len);
cmp::max(max_fixed_len, n.eval_usize(tcx, param_env))
}
(
ty::ConstKind::Value(ConstValue::Slice { start, end, .. }),
ty::Slice(_),
) => max_fixed_len = cmp::max(max_fixed_len, (end - start) as u64),
_ => {}
} }
} VarLen(prefix, suffix) => {
PatKind::Slice { ref prefix, slice: None, ref suffix } max_prefix_len = cmp::max(max_prefix_len, prefix);
| PatKind::Array { ref prefix, slice: None, ref suffix } => { max_suffix_len = cmp::max(max_suffix_len, suffix);
let fixed_len = prefix.len() as u64 + suffix.len() as u64; }
max_fixed_len = cmp::max(max_fixed_len, fixed_len); },
}
PatKind::Slice { ref prefix, slice: Some(_), ref suffix }
| PatKind::Array { ref prefix, slice: Some(_), ref suffix } => {
max_prefix_len = cmp::max(max_prefix_len, prefix.len() as u64);
max_suffix_len = cmp::max(max_suffix_len, suffix.len() as u64);
}
_ => {} _ => {}
} }
} }