Skip to content

Commit 8eba352

Browse files
authored
Rollup merge of #150184 - Zalathar:slice-len, r=saethlin
mir_build: Use the same length type for `TestableCase::Slice` and `TestKind::Len` If we convert the minimum length to `u64` up-front when creating `TestableCase::Slice`, we can avoid more conversions to `u64` later. There should be no change to compiler behaviour.
2 parents 7f3efbf + 19f74f4 commit 8eba352

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

compiler/rustc_mir_build/src/builder/matches/buckets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
218218
&TestKind::Len { len: test_len, op: BinOp::Eq },
219219
&TestableCase::Slice { len, variable_length },
220220
) => {
221-
match (test_len.cmp(&(len as u64)), variable_length) {
221+
match (test_len.cmp(&len), variable_length) {
222222
(Ordering::Equal, false) => {
223223
// on true, min_len = len = $actual_length,
224224
// on false, len != $actual_length
@@ -251,7 +251,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
251251
&TestableCase::Slice { len, variable_length },
252252
) => {
253253
// the test is `$actual_len >= test_len`
254-
match (test_len.cmp(&(len as u64)), variable_length) {
254+
match (test_len.cmp(&len), variable_length) {
255255
(Ordering::Equal, true) => {
256256
// $actual_len >= test_len = pat_len,
257257
// so we can match.

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<'tcx> MatchPairTree<'tcx> {
256256
None
257257
} else {
258258
Some(TestableCase::Slice {
259-
len: prefix.len() + suffix.len(),
259+
len: u64::try_from(prefix.len() + suffix.len()).unwrap(),
260260
variable_length: slice.is_some(),
261261
})
262262
}

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ enum TestableCase<'tcx> {
12641264
Variant { adt_def: ty::AdtDef<'tcx>, variant_index: VariantIdx },
12651265
Constant { value: ty::Value<'tcx> },
12661266
Range(Arc<PatRange<'tcx>>),
1267-
Slice { len: usize, variable_length: bool },
1267+
Slice { len: u64, variable_length: bool },
12681268
Deref { temp: Place<'tcx>, mutability: Mutability },
12691269
Never,
12701270
Or { pats: Box<[FlatPat<'tcx>]> },

compiler/rustc_mir_build/src/builder/matches/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4747

4848
TestableCase::Slice { len, variable_length } => {
4949
let op = if variable_length { BinOp::Ge } else { BinOp::Eq };
50-
TestKind::Len { len: len as u64, op }
50+
TestKind::Len { len, op }
5151
}
5252

5353
TestableCase::Deref { temp, mutability } => TestKind::Deref { temp, mutability },

0 commit comments

Comments
 (0)