Skip to content

Commit 2d08e94

Browse files
authored
Rollup merge of #130786 - DianQK:early_otherwise_branch_cleanup, r=oli-obk
mir-opt: a sub-BB of a cleanup BB must also be a cleanup BB in `EarlyOtherwiseBranch` Fixes #130769. r? `@cjgillot` or mir-opt
2 parents 3378a5e + d08738c commit 2d08e94

14 files changed

+739
-109
lines changed

compiler/rustc_middle/src/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1348,8 +1348,8 @@ pub struct BasicBlockData<'tcx> {
13481348
}
13491349

13501350
impl<'tcx> BasicBlockData<'tcx> {
1351-
pub fn new(terminator: Option<Terminator<'tcx>>) -> BasicBlockData<'tcx> {
1352-
BasicBlockData { statements: vec![], terminator, is_cleanup: false }
1351+
pub fn new(terminator: Option<Terminator<'tcx>>, is_cleanup: bool) -> BasicBlockData<'tcx> {
1352+
BasicBlockData { statements: vec![], terminator, is_cleanup }
13531353
}
13541354

13551355
/// Accessor for terminator.

compiler/rustc_mir_build/src/builder/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<'tcx> CFG<'tcx> {
1919
// it as #[inline(never)] to keep rustc's stack use in check.
2020
#[inline(never)]
2121
pub(crate) fn start_new_block(&mut self) -> BasicBlock {
22-
self.basic_blocks.push(BasicBlockData::new(None))
22+
self.basic_blocks.push(BasicBlockData::new(None, false))
2323
}
2424

2525
pub(crate) fn start_new_cleanup_block(&mut self) -> BasicBlock {

compiler/rustc_mir_build/src/builder/custom/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(super) fn build_custom_mir<'tcx>(
6464
};
6565

6666
body.local_decls.push(LocalDecl::new(return_ty, return_ty_span));
67-
body.basic_blocks_mut().push(BasicBlockData::new(None));
67+
body.basic_blocks_mut().push(BasicBlockData::new(None, false));
6868
body.source_scopes.push(SourceScopeData {
6969
span,
7070
parent_scope: None,

compiler/rustc_mir_build/src/builder/custom/parse.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
199199
match &self.thir[stmt].kind {
200200
StmtKind::Let { pattern, initializer: Some(initializer), .. } => {
201201
let (var, ..) = self.parse_var(pattern)?;
202-
let mut data = BasicBlockData::new(None);
203-
data.is_cleanup = parse_by_kind!(self, *initializer, _, "basic block declaration",
204-
@variant(mir_basic_block, Normal) => false,
205-
@variant(mir_basic_block, Cleanup) => true,
202+
let data = BasicBlockData::new(
203+
None,
204+
parse_by_kind!(self, *initializer, _, "basic block declaration",
205+
@variant(mir_basic_block, Normal) => false,
206+
@variant(mir_basic_block, Cleanup) => true,
207+
),
206208
);
207209
let block = self.body.basic_blocks_mut().push(data);
208210
self.block_map.insert(var, block);
@@ -308,8 +310,7 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
308310
ExprKind::Block { block } => &self.thir[*block],
309311
);
310312

311-
let mut data = BasicBlockData::new(None);
312-
data.is_cleanup = is_cleanup;
313+
let mut data = BasicBlockData::new(None, is_cleanup);
313314
for stmt_id in &*block.stmts {
314315
let stmt = self.statement_as_expr(*stmt_id)?;
315316
let span = self.thir[stmt].span;

0 commit comments

Comments
 (0)