Skip to content

Commit 3f91712

Browse files
committed
Reuse pat_constructor in split_grouped_ctors
1 parent e6e5513 commit 3f91712

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

src/librustc_mir/hair/pattern/_match.rs

+12-25
Original file line numberDiff line numberDiff line change
@@ -2096,32 +2096,19 @@ fn split_grouped_constructors<'p, 'tcx>(
20962096
let mut max_suffix_len = self_suffix;
20972097
let mut max_fixed_len = 0;
20982098

2099-
for row in matrix.heads() {
2100-
match *row.kind {
2101-
PatKind::Constant { value } => {
2102-
// extract the length of an array/slice from a constant
2103-
match (value.val, &value.ty.kind) {
2104-
(_, ty::Array(_, n)) => {
2105-
max_fixed_len =
2106-
cmp::max(max_fixed_len, n.eval_usize(tcx, param_env))
2107-
}
2108-
(
2109-
ty::ConstKind::Value(ConstValue::Slice { start, end, .. }),
2110-
ty::Slice(_),
2111-
) => max_fixed_len = cmp::max(max_fixed_len, (end - start) as u64),
2112-
_ => {}
2099+
let head_ctors =
2100+
matrix.heads().filter_map(|pat| pat_constructor(tcx, param_env, pat));
2101+
for ctor in head_ctors {
2102+
match ctor {
2103+
Slice(slice) => match slice.pattern_kind() {
2104+
FixedLen(len) => {
2105+
max_fixed_len = cmp::max(max_fixed_len, len);
21132106
}
2114-
}
2115-
PatKind::Slice { ref prefix, slice: None, ref suffix }
2116-
| PatKind::Array { ref prefix, slice: None, ref suffix } => {
2117-
let fixed_len = prefix.len() as u64 + suffix.len() as u64;
2118-
max_fixed_len = cmp::max(max_fixed_len, fixed_len);
2119-
}
2120-
PatKind::Slice { ref prefix, slice: Some(_), ref suffix }
2121-
| PatKind::Array { ref prefix, slice: Some(_), ref suffix } => {
2122-
max_prefix_len = cmp::max(max_prefix_len, prefix.len() as u64);
2123-
max_suffix_len = cmp::max(max_suffix_len, suffix.len() as u64);
2124-
}
2107+
VarLen(prefix, suffix) => {
2108+
max_prefix_len = cmp::max(max_prefix_len, prefix);
2109+
max_suffix_len = cmp::max(max_suffix_len, suffix);
2110+
}
2111+
},
21252112
_ => {}
21262113
}
21272114
}

0 commit comments

Comments
 (0)