@@ -5,13 +5,17 @@ use crate::dataflow::{Analysis, ResultsCursor};
5
5
use crate :: util:: storage:: AlwaysLiveLocals ;
6
6
7
7
use super :: MirPass ;
8
- use rustc_middle:: mir:: visit:: { PlaceContext , Visitor } ;
8
+ use rustc_middle:: mir:: {
9
+ interpret:: Scalar ,
10
+ visit:: { PlaceContext , Visitor } ,
11
+ } ;
9
12
use rustc_middle:: mir:: {
10
13
AggregateKind , BasicBlock , Body , BorrowKind , Local , Location , MirPhase , Operand , Rvalue ,
11
14
SourceScope , Statement , StatementKind , Terminator , TerminatorKind , VarDebugInfo ,
12
15
} ;
13
16
use rustc_middle:: ty:: relate:: { Relate , RelateResult , TypeRelation } ;
14
17
use rustc_middle:: ty:: { self , ParamEnv , Ty , TyCtxt } ;
18
+ use rustc_target:: abi:: Size ;
15
19
16
20
#[ derive( Copy , Clone , Debug ) ]
17
21
enum EdgeKind {
@@ -346,7 +350,25 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
346
350
) ,
347
351
) ;
348
352
}
349
- for ( _, target) in targets. iter ( ) {
353
+
354
+ let target_width = self . tcx . sess . target . pointer_width ;
355
+
356
+ let size = Size :: from_bits ( match switch_ty. kind ( ) {
357
+ ty:: Uint ( uint) => uint. normalize ( target_width) . bit_width ( ) . unwrap ( ) ,
358
+ ty:: Int ( int) => int. normalize ( target_width) . bit_width ( ) . unwrap ( ) ,
359
+ ty:: Char => 32 ,
360
+ ty:: Bool => 1 ,
361
+ other => bug ! ( "unhandled type: {:?}" , other) ,
362
+ } ) ;
363
+
364
+ for ( value, target) in targets. iter ( ) {
365
+ if Scalar :: < ( ) > :: try_from_uint ( value, size) . is_none ( ) {
366
+ self . fail (
367
+ location,
368
+ format ! ( "the value {:#x} is not a proper {:?}" , value, switch_ty) ,
369
+ )
370
+ }
371
+
350
372
self . check_edge ( location, target, EdgeKind :: Normal ) ;
351
373
}
352
374
self . check_edge ( location, targets. otherwise ( ) , EdgeKind :: Normal ) ;
0 commit comments