Skip to content

Commit

Permalink
Reuse pat_constructor in split_grouped_ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Nov 21, 2019
1 parent e6e5513 commit 3f91712
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2096,32 +2096,19 @@ fn split_grouped_constructors<'p, 'tcx>(
let mut max_suffix_len = self_suffix;
let mut max_fixed_len = 0;

for row in matrix.heads() {
match *row.kind {
PatKind::Constant { value } => {
// extract the length of an array/slice from a constant
match (value.val, &value.ty.kind) {
(_, ty::Array(_, n)) => {
max_fixed_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),
_ => {}
let head_ctors =
matrix.heads().filter_map(|pat| pat_constructor(tcx, param_env, pat));
for ctor in head_ctors {
match ctor {
Slice(slice) => match slice.pattern_kind() {
FixedLen(len) => {
max_fixed_len = cmp::max(max_fixed_len, len);
}
}
PatKind::Slice { ref prefix, slice: None, ref suffix }
| PatKind::Array { ref prefix, slice: None, ref 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);
}
VarLen(prefix, suffix) => {
max_prefix_len = cmp::max(max_prefix_len, prefix);
max_suffix_len = cmp::max(max_suffix_len, suffix);
}
},
_ => {}
}
}
Expand Down

0 comments on commit 3f91712

Please sign in to comment.