Skip to content

Commit 1296925

Browse files
committed
Split out a separate PatConstKind::Float
Unlike the other types covered by `PatConstKind::Other`, const-float patterns can also interact with range patterns.
1 parent b772999 commit 1296925

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
289289
if !test.overlaps(pat, self.tcx)? { Some(TestBranch::Failure) } else { None }
290290
}
291291
}
292-
(TestKind::Range(range), &TestableCase::Constant { value, kind: _ }) => {
292+
(
293+
TestKind::Range(range),
294+
&TestableCase::Constant {
295+
value,
296+
kind: PatConstKind::Bool | PatConstKind::IntOrChar | PatConstKind::Float,
297+
},
298+
) => {
293299
fully_matched = false;
294300
if !range.contains(value, self.tcx)? {
295301
// `value` is not contained in the testing range,
@@ -302,7 +308,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
302308

303309
(
304310
TestKind::Eq { value: test_val, .. },
305-
TestableCase::Constant { value: case_val, kind: _ },
311+
TestableCase::Constant {
312+
value: case_val,
313+
kind: PatConstKind::Float | PatConstKind::Other,
314+
},
306315
) => {
307316
if test_val == case_val {
308317
fully_matched = true;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ impl<'tcx> MatchPairTree<'tcx> {
171171
PatConstKind::Bool
172172
} else if pat_ty.is_integral() || pat_ty.is_char() {
173173
PatConstKind::IntOrChar
174+
} else if pat_ty.is_floating_point() {
175+
PatConstKind::Float
174176
} else {
175177
// FIXME(Zalathar): This still covers several different
176178
// categories (e.g. raw pointer, string, pattern-type)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,10 +1286,13 @@ enum PatConstKind {
12861286
/// Primitive unsigned/signed integer types, plus `char`.
12871287
/// These types interact nicely with `SwitchInt`.
12881288
IntOrChar,
1289+
/// Floating-point primitives, e.g. `f32`, `f64`.
1290+
/// These types don't support `SwitchInt` and require an equality test,
1291+
/// but can also interact with range pattern tests.
1292+
Float,
12891293
/// Any other constant-pattern is usually tested via some kind of equality
12901294
/// check. Types that might be encountered here include:
12911295
/// - `&str`
1292-
/// - floating-point primitives, e.g. `f32`, `f64`
12931296
/// - raw pointers derived from integer values
12941297
/// - pattern types, e.g. `pattern_type!(u32 is 1..)`
12951298
Other,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3838
TestableCase::Constant { value: _, kind: PatConstKind::IntOrChar } => {
3939
TestKind::SwitchInt
4040
}
41+
TestableCase::Constant { value, kind: PatConstKind::Float } => {
42+
TestKind::Eq { value, cast_ty: match_pair.pattern_ty }
43+
}
4144
TestableCase::Constant { value, kind: PatConstKind::Other } => {
4245
TestKind::Eq { value, cast_ty: match_pair.pattern_ty }
4346
}

0 commit comments

Comments
 (0)