Skip to content

Commit

Permalink
Stop using unpack! for BlockAnd<()>
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jul 8, 2024
1 parent d9b0e97 commit 5066e6c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 29 deletions.
22 changes: 11 additions & 11 deletions compiler/rustc_mir_build/src/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
StmtKind::Expr { scope, expr } => {
this.block_context.push(BlockFrame::Statement { ignores_expr_result: true });
let si = (*scope, source_info);
unpack!(
block = this.in_scope(si, LintLevel::Inherited, |this| {
block = this
.in_scope(si, LintLevel::Inherited, |this| {
this.stmt_expr(block, *expr, Some(*scope))
})
);
.unpack_block_and_unit();
}
StmtKind::Let {
remainder_scope,
Expand Down Expand Up @@ -166,14 +166,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let dummy_place = this.temp(this.tcx.types.never, else_block_span);
let failure_entry = this.cfg.start_new_block();
let failure_block;
unpack!(
failure_block = this.ast_block(
failure_block = this
.ast_block(
dummy_place,
failure_entry,
*else_block,
this.source_info(else_block_span),
)
);
.unpack_block_and_unit();
this.cfg.terminate(
failure_block,
this.source_info(else_block_span),
Expand Down Expand Up @@ -267,8 +267,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let initializer_span = this.thir[init].span;
let scope = (*init_scope, source_info);

unpack!(
block = this.in_scope(scope, *lint_level, |this| {
block = this
.in_scope(scope, *lint_level, |this| {
this.declare_bindings(
visibility_scope,
remainder_span,
Expand All @@ -279,7 +279,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.expr_into_pattern(block, &pattern, init)
// irrefutable pattern
})
)
.unpack_block_and_unit();
} else {
let scope = (*init_scope, source_info);
let _: BlockAnd<()> = this.in_scope(scope, *lint_level, |this| {
Expand Down Expand Up @@ -333,7 +333,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.block_context
.push(BlockFrame::TailExpr { tail_result_is_ignored, span: expr.span });

unpack!(block = this.expr_into_dest(destination, block, expr_id));
block = this.expr_into_dest(destination, block, expr_id).unpack_block_and_unit();
let popped = this.block_context.pop();

assert!(popped.is_some_and(|bf| bf.is_tail_expr()));
Expand All @@ -355,7 +355,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Finally, we pop all the let scopes before exiting out from the scope of block
// itself.
for scope in let_scope_stack.into_iter().rev() {
unpack!(block = this.pop_scope((*scope, source_info), block));
block = this.pop_scope((*scope, source_info), block).unpack_block_and_unit();
}
// Restore the original source scope.
this.source_scope = outer_source_scope;
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.cfg.push_assign(block, source_info, Place::from(result), box_);

// initialize the box contents:
unpack!(
block = this.expr_into_dest(
this.tcx.mk_place_deref(Place::from(result)),
block,
value,
)
);
block = this
.expr_into_dest(this.tcx.mk_place_deref(Place::from(result)), block, value)
.unpack_block_and_unit();
block.and(Rvalue::Use(Operand::Move(Place::from(result))))
}
ExprKind::Cast { source } => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/as_temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}

unpack!(block = this.expr_into_dest(temp_place, block, expr_id));
block = this.expr_into_dest(temp_place, block, expr_id).unpack_block_and_unit();

if let Some(temp_lifetime) = temp_lifetime {
this.schedule_drop(expr_span, temp_lifetime, temp, DropKind::Value);
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

// If there is an `else` arm, lower it into `else_blk`.
if let Some(else_expr) = else_opt {
unpack!(else_blk = this.expr_into_dest(destination, else_blk, else_expr));
else_blk = this
.expr_into_dest(destination, else_blk, else_expr)
.unpack_block_and_unit();
} else {
// There is no `else` arm, so we know both arms have type `()`.
// Generate the implicit `else {}` by assigning unit.
Expand Down Expand Up @@ -508,7 +510,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

// These cases don't actually need a destination
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
unpack!(block = this.stmt_expr(block, expr_id, None));
block = this.stmt_expr(block, expr_id, None).unpack_block_and_unit();
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
block.unit()
}
Expand All @@ -517,7 +519,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
| ExprKind::Break { .. }
| ExprKind::Return { .. }
| ExprKind::Become { .. } => {
unpack!(block = this.stmt_expr(block, expr_id, None));
block = this.stmt_expr(block, expr_id, None).unpack_block_and_unit();
// No assign, as these have type `!`.
block.unit()
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir_build/src/build/expr/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if lhs_expr.ty.needs_drop(this.tcx, this.param_env) {
let rhs = unpack!(block = this.as_local_rvalue(block, rhs));
let lhs = unpack!(block = this.as_place(block, lhs));
unpack!(block = this.build_drop_and_replace(block, lhs_expr.span, lhs, rhs));
block = this
.build_drop_and_replace(block, lhs_expr.span, lhs, rhs)
.unpack_block_and_unit();
} else {
let rhs = unpack!(block = this.as_local_rvalue(block, rhs));
let lhs = unpack!(block = this.as_place(block, lhs));
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
OutsideGuard,
ScheduleDrops::Yes,
);
unpack!(block = self.expr_into_dest(place, block, initializer_id));
block = self.expr_into_dest(place, block, initializer_id).unpack_block_and_unit();

// Inject a fake read, see comments on `FakeReadCause::ForLet`.
let source_info = self.source_info(irrefutable_pat.span);
Expand Down Expand Up @@ -665,7 +665,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
OutsideGuard,
ScheduleDrops::Yes,
);
unpack!(block = self.expr_into_dest(place, block, initializer_id));
block = self.expr_into_dest(place, block, initializer_id).unpack_block_and_unit();

// Inject a fake read, see comments on `FakeReadCause::ForLet`.
let pattern_source_info = self.source_info(irrefutable_pat.span);
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_mir_build/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ fn construct_const<'a, 'tcx>(
Builder::new(thir, infcx, def, hir_id, span, 0, const_ty, const_ty_span, None);

let mut block = START_BLOCK;
unpack!(block = builder.expr_into_dest(Place::return_place(), block, expr));
block = builder.expr_into_dest(Place::return_place(), block, expr).unpack_block_and_unit();

let source_info = builder.source_info(span);
builder.cfg.terminate(block, source_info, TerminatorKind::Return);
Expand Down Expand Up @@ -966,7 +966,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Some((Some(&place), span)),
);
let place_builder = PlaceBuilder::from(local);
unpack!(block = self.place_into_pattern(block, pat, place_builder, false));
block = self
.place_into_pattern(block, pat, place_builder, false)
.unpack_block_and_unit();
}
}
self.source_scope = original_source_scope;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.push_scope(region_scope);
let mut block;
let rv = unpack!(block = f(self));
unpack!(block = self.pop_scope(region_scope, block));
block = self.pop_scope(region_scope, block).unpack_block_and_unit();
self.source_scope = source_scope;
debug!(?block);
block.and(rv)
Expand Down Expand Up @@ -659,7 +659,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
(Some(destination), Some(value)) => {
debug!("stmt_expr Break val block_context.push(SubExpr)");
self.block_context.push(BlockFrame::SubExpr);
unpack!(block = self.expr_into_dest(destination, block, value));
block = self.expr_into_dest(destination, block, value).unpack_block_and_unit();
self.block_context.pop();
}
(Some(destination), None) => {
Expand Down

0 comments on commit 5066e6c

Please sign in to comment.