@@ -6,8 +6,7 @@ use rustc_middle::span_bug;
66use tracing:: debug;
77
88use crate :: builder:: Builder ;
9- use crate :: builder:: matches:: test:: is_switch_ty;
10- use crate :: builder:: matches:: { Candidate , Test , TestBranch , TestKind , TestableCase } ;
9+ use crate :: builder:: matches:: { Candidate , PatConstKind , Test , TestBranch , TestKind , TestableCase } ;
1110
1211/// Output of [`Builder::partition_candidates_into_buckets`].
1312pub ( crate ) struct PartitionedCandidates < ' tcx , ' b , ' c > {
@@ -157,11 +156,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
157156 //
158157 // FIXME(#29623) we could use PatKind::Range to rule
159158 // things out here, in some cases.
160- //
161- // FIXME(Zalathar): Is the `is_switch_ty` test unnecessary?
162- ( TestKind :: SwitchInt , & TestableCase :: Constant { value } )
163- if is_switch_ty ( match_pair. pattern_ty ) =>
164- {
159+ (
160+ TestKind :: SwitchInt ,
161+ & TestableCase :: Constant { value, kind : PatConstKind :: IntOrChar } ,
162+ ) => {
165163 // An important invariant of candidate bucketing is that a candidate
166164 // must not match in multiple branches. For `SwitchInt` tests, adding
167165 // a new value might invalidate that property for range patterns that
@@ -206,7 +204,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
206204 } )
207205 }
208206
209- ( TestKind :: If , TestableCase :: Constant { value } ) => {
207+ ( TestKind :: If , TestableCase :: Constant { value, kind : PatConstKind :: Bool } ) => {
210208 fully_matched = true ;
211209 let value = value. try_to_bool ( ) . unwrap_or_else ( || {
212210 span_bug ! ( test. span, "expected boolean value but got {value:?}" )
@@ -291,7 +289,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
291289 if !test. overlaps ( pat, self . tcx ) ? { Some ( TestBranch :: Failure ) } else { None }
292290 }
293291 }
294- ( TestKind :: Range ( range) , & TestableCase :: Constant { value } ) => {
292+ (
293+ TestKind :: Range ( range) ,
294+ & TestableCase :: Constant {
295+ value,
296+ kind : PatConstKind :: Bool | PatConstKind :: IntOrChar | PatConstKind :: Float ,
297+ } ,
298+ ) => {
295299 fully_matched = false ;
296300 if !range. contains ( value, self . tcx ) ? {
297301 // `value` is not contained in the testing range,
@@ -302,7 +306,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
302306 }
303307 }
304308
305- ( TestKind :: Eq { value : test_val, .. } , TestableCase :: Constant { value : case_val } ) => {
309+ (
310+ TestKind :: Eq { value : test_val, .. } ,
311+ TestableCase :: Constant {
312+ value : case_val,
313+ kind : PatConstKind :: Float | PatConstKind :: Other ,
314+ } ,
315+ ) => {
306316 if test_val == case_val {
307317 fully_matched = true ;
308318 Some ( TestBranch :: Success )
0 commit comments