@@ -118,9 +118,18 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
118
118
unreachable_targets. push ( index) ;
119
119
}
120
120
}
121
-
122
- let replace_otherwise_to_unreachable = allowed_variants. len ( ) <= 1
123
- && !body. basic_blocks [ targets. otherwise ( ) ] . is_empty_unreachable ( ) ;
121
+ let otherwise_is_empty_unreachable =
122
+ body. basic_blocks [ targets. otherwise ( ) ] . is_empty_unreachable ( ) ;
123
+ // After resolving https://github.com/llvm/llvm-project/issues/78578,
124
+ // we can remove the limit on the number of successors.
125
+ let otherwise_is_last_variant = !otherwise_is_empty_unreachable
126
+ && allowed_variants. len ( ) == 1
127
+ && !body. basic_blocks [ targets. otherwise ( ) ]
128
+ . terminator ( )
129
+ . successors ( )
130
+ . any ( |bb| body. basic_blocks [ bb] . terminator ( ) . successors ( ) . count ( ) >= 8 ) ;
131
+ let replace_otherwise_to_unreachable = otherwise_is_last_variant
132
+ || !otherwise_is_empty_unreachable && allowed_variants. is_empty ( ) ;
124
133
125
134
if unreachable_targets. is_empty ( ) && !replace_otherwise_to_unreachable {
126
135
continue ;
@@ -129,7 +138,6 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
129
138
let unreachable_block = patch. unreachable_no_cleanup_block ( ) ;
130
139
let mut targets = targets. clone ( ) ;
131
140
if replace_otherwise_to_unreachable {
132
- let otherwise_is_last_variant = !allowed_variants. is_empty ( ) ;
133
141
if otherwise_is_last_variant {
134
142
#[ allow( rustc:: potential_query_instability) ]
135
143
let last_variant = * allowed_variants. iter ( ) . next ( ) . unwrap ( ) ;
0 commit comments