Skip to content

Commit 03d5f9b

Browse files
committed
rustc_mir_build: drive-by-cleaup: replace nested ifs with a match
1 parent 5ae51d6 commit 03d5f9b

File tree

1 file changed

+9
-6
lines changed
  • compiler/rustc_mir_build/src/build

1 file changed

+9
-6
lines changed

compiler/rustc_mir_build/src/build/scope.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,24 +644,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
644644
}
645645
};
646646

647-
if let Some(destination) = destination {
648-
if let Some(value) = value {
647+
match (destination, value) {
648+
(Some(destination), Some(value)) => {
649649
debug!("stmt_expr Break val block_context.push(SubExpr)");
650650
self.block_context.push(BlockFrame::SubExpr);
651651
unpack!(block = self.expr_into_dest(destination, block, value));
652652
self.block_context.pop();
653-
} else {
653+
}
654+
(Some(destination), None) => {
654655
self.cfg.push_assign_unit(block, source_info, destination, self.tcx)
655656
}
656-
} else {
657-
assert!(value.is_none(), "`return` and `break` should have a destination");
658-
if self.tcx.sess.instrument_coverage() {
657+
(None, Some(_)) => {
658+
panic!("`return`, `become` and `break` with value and must have a destination")
659+
}
660+
(None, None) if self.tcx.sess.instrument_coverage() => {
659661
// Unlike `break` and `return`, which push an `Assign` statement to MIR, from which
660662
// a Coverage code region can be generated, `continue` needs no `Assign`; but
661663
// without one, the `InstrumentCoverage` MIR pass cannot generate a code region for
662664
// `continue`. Coverage will be missing unless we add a dummy `Assign` to MIR.
663665
self.add_dummy_assignment(span, block, source_info);
664666
}
667+
(None, None) => {}
665668
}
666669

667670
let region_scope = self.scopes.breakable_scopes[break_index].region_scope;

0 commit comments

Comments
 (0)