@@ -55,6 +55,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
5555 reachable_blocks : traversal:: reachable_as_bitset ( body) ,
5656 storage_liveness,
5757 place_cache : Vec :: new ( ) ,
58+ value_cache : Vec :: new ( ) ,
5859 }
5960 . visit_body ( body) ;
6061 }
@@ -109,6 +110,7 @@ struct TypeChecker<'a, 'tcx> {
109110 reachable_blocks : BitSet < BasicBlock > ,
110111 storage_liveness : ResultsCursor < ' a , ' tcx , MaybeStorageLive > ,
111112 place_cache : Vec < PlaceRef < ' tcx > > ,
113+ value_cache : Vec < u128 > ,
112114}
113115
114116impl < ' a , ' tcx > TypeChecker < ' a , ' tcx > {
@@ -398,6 +400,22 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
398400 self . check_edge ( location, target, EdgeKind :: Normal ) ;
399401 }
400402 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+ }
401419 }
402420 TerminatorKind :: Drop { target, unwind, .. } => {
403421 self . check_edge ( location, * target, EdgeKind :: Normal ) ;
0 commit comments