@@ -55,6 +55,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
55
55
reachable_blocks : traversal:: reachable_as_bitset ( body) ,
56
56
storage_liveness,
57
57
place_cache : Vec :: new ( ) ,
58
+ value_cache : Vec :: new ( ) ,
58
59
}
59
60
. visit_body ( body) ;
60
61
}
@@ -109,6 +110,7 @@ struct TypeChecker<'a, 'tcx> {
109
110
reachable_blocks : BitSet < BasicBlock > ,
110
111
storage_liveness : ResultsCursor < ' a , ' tcx , MaybeStorageLive > ,
111
112
place_cache : Vec < PlaceRef < ' tcx > > ,
113
+ value_cache : Vec < u128 > ,
112
114
}
113
115
114
116
impl < ' a , ' tcx > TypeChecker < ' a , ' tcx > {
@@ -398,6 +400,22 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
398
400
self . check_edge ( location, target, EdgeKind :: Normal ) ;
399
401
}
400
402
self . check_edge ( location, targets. otherwise ( ) , EdgeKind :: Normal ) ;
403
+
404
+ self . value_cache . clear ( ) ;
405
+ self . value_cache . extend ( targets. iter ( ) . map ( |( value, _) | value) ) ;
406
+ let all_len = self . value_cache . len ( ) ;
407
+ self . value_cache . sort_unstable ( ) ;
408
+ self . value_cache . dedup ( ) ;
409
+ let has_duplicates = all_len != self . value_cache . len ( ) ;
410
+ if has_duplicates {
411
+ self . fail (
412
+ location,
413
+ format ! (
414
+ "duplicated values in `SwitchInt` terminator: {:?}" ,
415
+ terminator. kind,
416
+ ) ,
417
+ ) ;
418
+ }
401
419
}
402
420
TerminatorKind :: Drop { target, unwind, .. } => {
403
421
self . check_edge ( location, * target, EdgeKind :: Normal ) ;
0 commit comments