Skip to content

Commit 102bda4

Browse files
committed
Remove restrictions on small enum statements such as Order, Option or Result
`early-tailduplication` is only a problem when there are a significant number of branches.
1 parent f8656ef commit 102bda4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

compiler/rustc_mir_transform/src/unreachable_enum_branching.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ impl<'tcx> MirPass<'tcx> for UnreachableEnumBranching {
175175
// ```
176176
let otherwise_is_last_variant = !otherwise_is_empty_unreachable
177177
&& allowed_variants.len() == 1
178-
&& check_successors(&body.basic_blocks, targets.otherwise());
178+
// Despite the LLVM issue, we hope that small enum can still be transformed.
179+
// This is valuable for both `a <= b` and `if let Some/Ok(v)`.
180+
&& (targets.all_targets().len() <= 3
181+
|| check_successors(&body.basic_blocks, targets.otherwise()));
179182
let replace_otherwise_to_unreachable = otherwise_is_last_variant
180183
|| (!otherwise_is_empty_unreachable && allowed_variants.is_empty());
181184

0 commit comments

Comments
 (0)