mir: Add a new method to statement

Avoid introducing a large number of changes when adding optional initialization fields.
This commit is contained in:
dianqk
2025-06-08 15:30:18 +08:00
parent 5ca574e85b
commit 9f9cd5e283
30 changed files with 295 additions and 330 deletions

View File

@@ -354,15 +354,15 @@ fn optimize_use_clone<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let destination_block = target.unwrap(); let destination_block = target.unwrap();
bb.statements.push(mir::Statement { bb.statements.push(mir::Statement::new(
source_info: bb.terminator().source_info, bb.terminator().source_info,
kind: mir::StatementKind::Assign(Box::new(( mir::StatementKind::Assign(Box::new((
*destination, *destination,
mir::Rvalue::Use(mir::Operand::Copy( mir::Rvalue::Use(mir::Operand::Copy(
arg_place.project_deeper(&[mir::ProjectionElem::Deref], tcx), arg_place.project_deeper(&[mir::ProjectionElem::Deref], tcx),
)), )),
))), ))),
}); ));
bb.terminator_mut().kind = mir::TerminatorKind::Goto { target: destination_block }; bb.terminator_mut().kind = mir::TerminatorKind::Goto { target: destination_block };
} }

View File

@@ -16,12 +16,16 @@ pub struct Statement<'tcx> {
pub kind: StatementKind<'tcx>, pub kind: StatementKind<'tcx>,
} }
impl Statement<'_> { impl<'tcx> Statement<'tcx> {
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids /// Changes a statement to a nop. This is both faster than deleting instructions and avoids
/// invalidating statement indices in `Location`s. /// invalidating statement indices in `Location`s.
pub fn make_nop(&mut self) { pub fn make_nop(&mut self) {
self.kind = StatementKind::Nop self.kind = StatementKind::Nop
} }
pub fn new(source_info: SourceInfo, kind: StatementKind<'tcx>) -> Self {
Statement { source_info, kind }
}
} }
impl<'tcx> StatementKind<'tcx> { impl<'tcx> StatementKind<'tcx> {

View File

@@ -42,7 +42,7 @@ impl<'tcx> CFG<'tcx> {
) { ) {
self.push( self.push(
block, block,
Statement { source_info, kind: StatementKind::Assign(Box::new((place, rvalue))) }, Statement::new(source_info, StatementKind::Assign(Box::new((place, rvalue)))),
); );
} }
@@ -88,7 +88,7 @@ impl<'tcx> CFG<'tcx> {
place: Place<'tcx>, place: Place<'tcx>,
) { ) {
let kind = StatementKind::FakeRead(Box::new((cause, place))); let kind = StatementKind::FakeRead(Box::new((cause, place)));
let stmt = Statement { source_info, kind }; let stmt = Statement::new(source_info, kind);
self.push(block, stmt); self.push(block, stmt);
} }
@@ -99,7 +99,7 @@ impl<'tcx> CFG<'tcx> {
place: Place<'tcx>, place: Place<'tcx>,
) { ) {
let kind = StatementKind::PlaceMention(Box::new(place)); let kind = StatementKind::PlaceMention(Box::new(place));
let stmt = Statement { source_info, kind }; let stmt = Statement::new(source_info, kind);
self.push(block, stmt); self.push(block, stmt);
} }
@@ -110,7 +110,7 @@ impl<'tcx> CFG<'tcx> {
/// syntax (e.g. `continue` or `if !`) that would otherwise not appear in MIR. /// syntax (e.g. `continue` or `if !`) that would otherwise not appear in MIR.
pub(crate) fn push_coverage_span_marker(&mut self, block: BasicBlock, source_info: SourceInfo) { pub(crate) fn push_coverage_span_marker(&mut self, block: BasicBlock, source_info: SourceInfo) {
let kind = StatementKind::Coverage(coverage::CoverageKind::SpanMarker); let kind = StatementKind::Coverage(coverage::CoverageKind::SpanMarker);
let stmt = Statement { source_info, kind }; let stmt = Statement::new(source_info, kind);
self.push(block, stmt); self.push(block, stmt);
} }

View File

@@ -61,10 +61,10 @@ impl BlockMarkerGen {
block: BasicBlock, block: BasicBlock,
) -> BlockMarkerId { ) -> BlockMarkerId {
let id = self.next_block_marker_id(); let id = self.next_block_marker_id();
let marker_statement = mir::Statement { let marker_statement = mir::Statement::new(
source_info, source_info,
kind: mir::StatementKind::Coverage(CoverageKind::BlockMarker { id }), mir::StatementKind::Coverage(CoverageKind::BlockMarker { id }),
}; );
cfg.push(block, marker_statement); cfg.push(block, marker_statement);
id id

View File

@@ -315,10 +315,8 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
let stmt = self.statement_as_expr(*stmt_id)?; let stmt = self.statement_as_expr(*stmt_id)?;
let span = self.thir[stmt].span; let span = self.thir[stmt].span;
let statement = self.parse_statement(stmt)?; let statement = self.parse_statement(stmt)?;
data.statements.push(Statement { data.statements
source_info: SourceInfo { span, scope: self.source_scope }, .push(Statement::new(SourceInfo { span, scope: self.source_scope }, statement));
kind: statement,
});
} }
let Some(trailing) = block.expr else { return Err(self.expr_error(expr_id, "terminator")) }; let Some(trailing) = block.expr else { return Err(self.expr_error(expr_id, "terminator")) };

View File

@@ -489,16 +489,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let place = place_builder.to_place(this); let place = place_builder.to_place(this);
this.cfg.push( this.cfg.push(
block, block,
Statement { Statement::new(
source_info: ty_source_info, ty_source_info,
kind: StatementKind::AscribeUserType( StatementKind::AscribeUserType(
Box::new(( Box::new((
place, place,
UserTypeProjection { base: annotation_index, projs: vec![] }, UserTypeProjection { base: annotation_index, projs: vec![] },
)), )),
Variance::Invariant, Variance::Invariant,
), ),
}, ),
); );
} }
block.and(place_builder) block.and(place_builder)
@@ -518,16 +518,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}); });
this.cfg.push( this.cfg.push(
block, block,
Statement { Statement::new(
source_info: ty_source_info, ty_source_info,
kind: StatementKind::AscribeUserType( StatementKind::AscribeUserType(
Box::new(( Box::new((
Place::from(temp), Place::from(temp),
UserTypeProjection { base: annotation_index, projs: vec![] }, UserTypeProjection { base: annotation_index, projs: vec![] },
)), )),
Variance::Invariant, Variance::Invariant,
), ),
}, ),
); );
} }
block.and(PlaceBuilder::from(temp)) block.and(PlaceBuilder::from(temp))

View File

@@ -175,10 +175,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// and therefore is not considered during coroutine auto-trait // and therefore is not considered during coroutine auto-trait
// determination. See the comment about `box` at `yield_in_scope`. // determination. See the comment about `box` at `yield_in_scope`.
let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span)); let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span));
this.cfg.push( this.cfg
block, .push(block, Statement::new(source_info, StatementKind::StorageLive(result)));
Statement { source_info, kind: StatementKind::StorageLive(result) },
);
if let Some(scope) = scope.temp_lifetime { if let Some(scope) = scope.temp_lifetime {
// schedule a shallow free of that memory, lest we unwind: // schedule a shallow free of that memory, lest we unwind:
this.schedule_drop_storage_and_value(expr_span, scope, result); this.schedule_drop_storage_and_value(expr_span, scope, result);
@@ -278,12 +276,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}; };
this.cfg.push( this.cfg.push(
block, block,
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::Intrinsic(Box::new( StatementKind::Intrinsic(Box::new(NonDivergingIntrinsic::Assume(
NonDivergingIntrinsic::Assume(Operand::Move(assert_place)), Operand::Move(assert_place),
)), ))),
}, ),
); );
} }
@@ -789,7 +787,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let source_info = this.source_info(upvar_span); let source_info = this.source_info(upvar_span);
let temp = this.local_decls.push(LocalDecl::new(upvar_ty, upvar_span)); let temp = this.local_decls.push(LocalDecl::new(upvar_ty, upvar_span));
this.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(temp) }); this.cfg.push(block, Statement::new(source_info, StatementKind::StorageLive(temp)));
let arg_place_builder = unpack!(block = this.as_place_builder(block, arg)); let arg_place_builder = unpack!(block = this.as_place_builder(block, arg));

View File

@@ -102,8 +102,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if let Block { expr: None, targeted_by_break: false, .. } = this.thir[block] if let Block { expr: None, targeted_by_break: false, .. } = this.thir[block]
&& expr_ty.is_never() => {} && expr_ty.is_never() => {}
_ => { _ => {
this.cfg this.cfg.push(block, Statement::new(source_info, StatementKind::StorageLive(temp)));
.push(block, Statement { source_info, kind: StatementKind::StorageLive(temp) });
// In constants, `temp_lifetime` is `None` for temporaries that // In constants, `temp_lifetime` is `None` for temporaries that
// live for the `'static` lifetime. Thus we do not drop these // live for the `'static` lifetime. Thus we do not drop these

View File

@@ -646,9 +646,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let base = self.canonical_user_type_annotations.push(annotation.clone()); let base = self.canonical_user_type_annotations.push(annotation.clone());
self.cfg.push( self.cfg.push(
block, block,
Statement { Statement::new(
source_info: ty_source_info, ty_source_info,
kind: StatementKind::AscribeUserType( StatementKind::AscribeUserType(
Box::new((place, UserTypeProjection { base, projs: Vec::new() })), Box::new((place, UserTypeProjection { base, projs: Vec::new() })),
// We always use invariant as the variance here. This is because the // We always use invariant as the variance here. This is because the
// variance field from the ascription refers to the variance to use // variance field from the ascription refers to the variance to use
@@ -666,7 +666,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// `<expr>`. // `<expr>`.
ty::Invariant, ty::Invariant,
), ),
}, ),
); );
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard); self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
@@ -828,7 +828,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
) -> Place<'tcx> { ) -> Place<'tcx> {
let local_id = self.var_local_id(var, for_guard); let local_id = self.var_local_id(var, for_guard);
let source_info = self.source_info(span); let source_info = self.source_info(span);
self.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(local_id) }); self.cfg.push(block, Statement::new(source_info, StatementKind::StorageLive(local_id)));
// Although there is almost always scope for given variable in corner cases // Although there is almost always scope for given variable in corner cases
// like #92893 we might get variable with no scope. // like #92893 we might get variable with no scope.
if let Some(region_scope) = self.region_scope_tree.var_scope(var.0.local_id) if let Some(region_scope) = self.region_scope_tree.var_scope(var.0.local_id)
@@ -2578,16 +2578,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let base = self.canonical_user_type_annotations.push(ascription.annotation); let base = self.canonical_user_type_annotations.push(ascription.annotation);
self.cfg.push( self.cfg.push(
block, block,
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::AscribeUserType( StatementKind::AscribeUserType(
Box::new(( Box::new((
ascription.source, ascription.source,
UserTypeProjection { base, projs: Vec::new() }, UserTypeProjection { base, projs: Vec::new() },
)), )),
ascription.variance, ascription.variance,
), ),
}, ),
); );
} }
} }

View File

@@ -431,13 +431,13 @@ impl DropTree {
cfg.terminate(block, drop_node.data.source_info, terminator); cfg.terminate(block, drop_node.data.source_info, terminator);
} }
DropKind::ForLint => { DropKind::ForLint => {
let stmt = Statement { let stmt = Statement::new(
source_info: drop_node.data.source_info, drop_node.data.source_info,
kind: StatementKind::BackwardIncompatibleDropHint { StatementKind::BackwardIncompatibleDropHint {
place: Box::new(drop_node.data.local.into()), place: Box::new(drop_node.data.local.into()),
reason: BackwardIncompatibleDropReason::Edition2024, reason: BackwardIncompatibleDropReason::Edition2024,
}, },
}; );
cfg.push(block, stmt); cfg.push(block, stmt);
let target = blocks[drop_node.next].unwrap(); let target = blocks[drop_node.next].unwrap();
if target != block { if target != block {
@@ -454,10 +454,10 @@ impl DropTree {
// Root nodes don't correspond to a drop. // Root nodes don't correspond to a drop.
DropKind::Storage if drop_idx == ROOT_NODE => {} DropKind::Storage if drop_idx == ROOT_NODE => {}
DropKind::Storage => { DropKind::Storage => {
let stmt = Statement { let stmt = Statement::new(
source_info: drop_node.data.source_info, drop_node.data.source_info,
kind: StatementKind::StorageDead(drop_node.data.local), StatementKind::StorageDead(drop_node.data.local),
}; );
cfg.push(block, stmt); cfg.push(block, stmt);
let target = blocks[drop_node.next].unwrap(); let target = blocks[drop_node.next].unwrap();
if target != block { if target != block {
@@ -1124,13 +1124,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
DropKind::ForLint => { DropKind::ForLint => {
self.cfg.push( self.cfg.push(
block, block,
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::BackwardIncompatibleDropHint { StatementKind::BackwardIncompatibleDropHint {
place: Box::new(local.into()), place: Box::new(local.into()),
reason: BackwardIncompatibleDropReason::Edition2024, reason: BackwardIncompatibleDropReason::Edition2024,
}, },
}, ),
); );
} }
DropKind::Storage => { DropKind::Storage => {
@@ -1138,7 +1138,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
assert!(local.index() > self.arg_count); assert!(local.index() > self.arg_count);
self.cfg.push( self.cfg.push(
block, block,
Statement { source_info, kind: StatementKind::StorageDead(local) }, Statement::new(source_info, StatementKind::StorageDead(local)),
); );
} }
} }
@@ -1880,13 +1880,13 @@ where
cfg.push( cfg.push(
block, block,
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::BackwardIncompatibleDropHint { StatementKind::BackwardIncompatibleDropHint {
place: Box::new(local.into()), place: Box::new(local.into()),
reason: BackwardIncompatibleDropReason::Edition2024, reason: BackwardIncompatibleDropReason::Edition2024,
}, },
}, ),
); );
} }
DropKind::Storage => { DropKind::Storage => {
@@ -1910,7 +1910,7 @@ where
} }
// Only temps and vars need their storage dead. // Only temps and vars need their storage dead.
assert!(local.index() > arg_count); assert!(local.index() > arg_count);
cfg.push(block, Statement { source_info, kind: StatementKind::StorageDead(local) }); cfg.push(block, Statement::new(source_info, StatementKind::StorageDead(local)));
} }
} }
} }

View File

@@ -17,7 +17,7 @@ fn mock_body<'tcx>() -> mir::Body<'tcx> {
let mut blocks = IndexVec::new(); let mut blocks = IndexVec::new();
let mut block = |n, kind| { let mut block = |n, kind| {
let nop = mir::Statement { source_info, kind: mir::StatementKind::Nop }; let nop = mir::Statement::new(source_info, mir::StatementKind::Nop);
blocks.push(mir::BasicBlockData { blocks.push(mir::BasicBlockData {
statements: std::iter::repeat(&nop).cloned().take(n).collect(), statements: std::iter::repeat(&nop).cloned().take(n).collect(),

View File

@@ -94,7 +94,7 @@ fn add_move_for_packed_drop<'tcx>(
let temp = patch.new_temp(ty, source_info.span); let temp = patch.new_temp(ty, source_info.span);
let storage_dead_block = patch.new_block(BasicBlockData { let storage_dead_block = patch.new_block(BasicBlockData {
statements: vec![Statement { source_info, kind: StatementKind::StorageDead(temp) }], statements: vec![Statement::new(source_info, StatementKind::StorageDead(temp))],
terminator: Some(Terminator { source_info, kind: TerminatorKind::Goto { target } }), terminator: Some(Terminator { source_info, kind: TerminatorKind::Goto { target } }),
is_cleanup, is_cleanup,
}); });

View File

@@ -81,9 +81,11 @@ impl<'tcx> crate::MirPass<'tcx> for AddRetag {
// Emit their retags. // Emit their retags.
basic_blocks[START_BLOCK].statements.splice( basic_blocks[START_BLOCK].statements.splice(
0..0, 0..0,
places.map(|(place, source_info)| Statement { places.map(|(place, source_info)| {
source_info, Statement::new(
kind: StatementKind::Retag(RetagKind::FnEntry, Box::new(place)), source_info,
StatementKind::Retag(RetagKind::FnEntry, Box::new(place)),
)
}), }),
); );
} }
@@ -113,10 +115,10 @@ impl<'tcx> crate::MirPass<'tcx> for AddRetag {
for (source_info, dest_place, dest_block) in returns { for (source_info, dest_place, dest_block) in returns {
basic_blocks[dest_block].statements.insert( basic_blocks[dest_block].statements.insert(
0, 0,
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::Retag(RetagKind::Default, Box::new(dest_place)), StatementKind::Retag(RetagKind::Default, Box::new(dest_place)),
}, ),
); );
} }
@@ -174,10 +176,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddRetag {
let source_info = block_data.statements[i].source_info; let source_info = block_data.statements[i].source_info;
block_data.statements.insert( block_data.statements.insert(
i + 1, i + 1,
Statement { Statement::new(source_info, StatementKind::Retag(retag_kind, Box::new(place))),
source_info,
kind: StatementKind::Retag(retag_kind, Box::new(place)),
},
); );
} }
} }

View File

@@ -51,22 +51,18 @@ fn insert_alignment_check<'tcx>(
let const_raw_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit); let const_raw_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit);
let rvalue = Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(pointer), const_raw_ptr); let rvalue = Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(pointer), const_raw_ptr);
let thin_ptr = local_decls.push(LocalDecl::with_source_info(const_raw_ptr, source_info)).into(); let thin_ptr = local_decls.push(LocalDecl::with_source_info(const_raw_ptr, source_info)).into();
stmts stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((thin_ptr, rvalue)))));
.push(Statement { source_info, kind: StatementKind::Assign(Box::new((thin_ptr, rvalue))) });
// Transmute the pointer to a usize (equivalent to `ptr.addr()`). // Transmute the pointer to a usize (equivalent to `ptr.addr()`).
let rvalue = Rvalue::Cast(CastKind::Transmute, Operand::Copy(thin_ptr), tcx.types.usize); let rvalue = Rvalue::Cast(CastKind::Transmute, Operand::Copy(thin_ptr), tcx.types.usize);
let addr = local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into(); let addr = local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();
stmts.push(Statement { source_info, kind: StatementKind::Assign(Box::new((addr, rvalue))) }); stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((addr, rvalue)))));
// Get the alignment of the pointee // Get the alignment of the pointee
let alignment = let alignment =
local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into(); local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();
let rvalue = Rvalue::NullaryOp(NullOp::AlignOf, pointee_ty); let rvalue = Rvalue::NullaryOp(NullOp::AlignOf, pointee_ty);
stmts.push(Statement { stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((alignment, rvalue)))));
source_info,
kind: StatementKind::Assign(Box::new((alignment, rvalue))),
});
// Subtract 1 from the alignment to get the alignment mask // Subtract 1 from the alignment to get the alignment mask
let alignment_mask = let alignment_mask =
@@ -76,13 +72,13 @@ fn insert_alignment_check<'tcx>(
user_ty: None, user_ty: None,
const_: Const::Val(ConstValue::Scalar(Scalar::from_target_usize(1, &tcx)), tcx.types.usize), const_: Const::Val(ConstValue::Scalar(Scalar::from_target_usize(1, &tcx)), tcx.types.usize),
})); }));
stmts.push(Statement { stmts.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
alignment_mask, alignment_mask,
Rvalue::BinaryOp(BinOp::Sub, Box::new((Operand::Copy(alignment), one))), Rvalue::BinaryOp(BinOp::Sub, Box::new((Operand::Copy(alignment), one))),
))), ))),
}); ));
// If this target does not have reliable alignment, further limit the mask by anding it with // If this target does not have reliable alignment, further limit the mask by anding it with
// the mask for the highest reliable alignment. // the mask for the highest reliable alignment.
@@ -99,31 +95,31 @@ fn insert_alignment_check<'tcx>(
tcx.types.usize, tcx.types.usize,
), ),
})); }));
stmts.push(Statement { stmts.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
alignment_mask, alignment_mask,
Rvalue::BinaryOp( Rvalue::BinaryOp(
BinOp::BitAnd, BinOp::BitAnd,
Box::new((Operand::Copy(alignment_mask), max_mask)), Box::new((Operand::Copy(alignment_mask), max_mask)),
), ),
))), ))),
}); ));
} }
// BitAnd the alignment mask with the pointer // BitAnd the alignment mask with the pointer
let alignment_bits = let alignment_bits =
local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into(); local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();
stmts.push(Statement { stmts.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
alignment_bits, alignment_bits,
Rvalue::BinaryOp( Rvalue::BinaryOp(
BinOp::BitAnd, BinOp::BitAnd,
Box::new((Operand::Copy(addr), Operand::Copy(alignment_mask))), Box::new((Operand::Copy(addr), Operand::Copy(alignment_mask))),
), ),
))), ))),
}); ));
// Check if the alignment bits are all zero // Check if the alignment bits are all zero
let is_ok = local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into(); let is_ok = local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into();
@@ -132,13 +128,13 @@ fn insert_alignment_check<'tcx>(
user_ty: None, user_ty: None,
const_: Const::Val(ConstValue::Scalar(Scalar::from_target_usize(0, &tcx)), tcx.types.usize), const_: Const::Val(ConstValue::Scalar(Scalar::from_target_usize(0, &tcx)), tcx.types.usize),
})); }));
stmts.push(Statement { stmts.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
is_ok, is_ok,
Rvalue::BinaryOp(BinOp::Eq, Box::new((Operand::Copy(alignment_bits), zero.clone()))), Rvalue::BinaryOp(BinOp::Eq, Box::new((Operand::Copy(alignment_bits), zero.clone()))),
))), ))),
}); ));
// Emit a check that asserts on the alignment and otherwise triggers a // Emit a check that asserts on the alignment and otherwise triggers a
// AssertKind::MisalignedPointerDereference. // AssertKind::MisalignedPointerDereference.

View File

@@ -41,13 +41,12 @@ fn insert_null_check<'tcx>(
let const_raw_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit); let const_raw_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit);
let rvalue = Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(pointer), const_raw_ptr); let rvalue = Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(pointer), const_raw_ptr);
let thin_ptr = local_decls.push(LocalDecl::with_source_info(const_raw_ptr, source_info)).into(); let thin_ptr = local_decls.push(LocalDecl::with_source_info(const_raw_ptr, source_info)).into();
stmts stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((thin_ptr, rvalue)))));
.push(Statement { source_info, kind: StatementKind::Assign(Box::new((thin_ptr, rvalue))) });
// Transmute the pointer to a usize (equivalent to `ptr.addr()`). // Transmute the pointer to a usize (equivalent to `ptr.addr()`).
let rvalue = Rvalue::Cast(CastKind::Transmute, Operand::Copy(thin_ptr), tcx.types.usize); let rvalue = Rvalue::Cast(CastKind::Transmute, Operand::Copy(thin_ptr), tcx.types.usize);
let addr = local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into(); let addr = local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();
stmts.push(Statement { source_info, kind: StatementKind::Assign(Box::new((addr, rvalue))) }); stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((addr, rvalue)))));
let zero = Operand::Constant(Box::new(ConstOperand { let zero = Operand::Constant(Box::new(ConstOperand {
span: source_info.span, span: source_info.span,
@@ -71,24 +70,24 @@ fn insert_null_check<'tcx>(
let rvalue = Rvalue::NullaryOp(NullOp::SizeOf, pointee_ty); let rvalue = Rvalue::NullaryOp(NullOp::SizeOf, pointee_ty);
let sizeof_pointee = let sizeof_pointee =
local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into(); local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();
stmts.push(Statement { stmts.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new((sizeof_pointee, rvalue))), StatementKind::Assign(Box::new((sizeof_pointee, rvalue))),
}); ));
// Check that the pointee is not a ZST. // Check that the pointee is not a ZST.
let is_pointee_not_zst = let is_pointee_not_zst =
local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into(); local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into();
stmts.push(Statement { stmts.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
is_pointee_not_zst, is_pointee_not_zst,
Rvalue::BinaryOp( Rvalue::BinaryOp(
BinOp::Ne, BinOp::Ne,
Box::new((Operand::Copy(sizeof_pointee), zero.clone())), Box::new((Operand::Copy(sizeof_pointee), zero.clone())),
), ),
))), ))),
}); ));
// Pointer needs to be checked only if pointee is not a ZST. // Pointer needs to be checked only if pointee is not a ZST.
Operand::Copy(is_pointee_not_zst) Operand::Copy(is_pointee_not_zst)
@@ -97,38 +96,38 @@ fn insert_null_check<'tcx>(
// Check whether the pointer is null. // Check whether the pointer is null.
let is_null = local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into(); let is_null = local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into();
stmts.push(Statement { stmts.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
is_null, is_null,
Rvalue::BinaryOp(BinOp::Eq, Box::new((Operand::Copy(addr), zero))), Rvalue::BinaryOp(BinOp::Eq, Box::new((Operand::Copy(addr), zero))),
))), ))),
}); ));
// We want to throw an exception if the pointer is null and the pointee is not unconditionally // We want to throw an exception if the pointer is null and the pointee is not unconditionally
// allowed (which for all non-borrow place uses, is when the pointee is ZST). // allowed (which for all non-borrow place uses, is when the pointee is ZST).
let should_throw_exception = let should_throw_exception =
local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into(); local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into();
stmts.push(Statement { stmts.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
should_throw_exception, should_throw_exception,
Rvalue::BinaryOp( Rvalue::BinaryOp(
BinOp::BitAnd, BinOp::BitAnd,
Box::new((Operand::Copy(is_null), pointee_should_be_checked)), Box::new((Operand::Copy(is_null), pointee_should_be_checked)),
), ),
))), ))),
}); ));
// The final condition whether this pointer usage is ok or not. // The final condition whether this pointer usage is ok or not.
let is_ok = local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into(); let is_ok = local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into();
stmts.push(Statement { stmts.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
is_ok, is_ok,
Rvalue::UnaryOp(UnOp::Not, Operand::Copy(should_throw_exception)), Rvalue::UnaryOp(UnOp::Not, Operand::Copy(should_throw_exception)),
))), ))),
}); ));
// Emit a PointerCheck that asserts on the condition and otherwise triggers // Emit a PointerCheck that asserts on the condition and otherwise triggers
// a AssertKind::NullPointerDereference. // a AssertKind::NullPointerDereference.

View File

@@ -252,10 +252,10 @@ impl<'tcx> TransformVisitor<'tcx> {
} }
}; };
let statements = vec![Statement { let statements = vec![Statement::new(
kind: StatementKind::Assign(Box::new((Place::return_place(), none_value))),
source_info, source_info,
}]; StatementKind::Assign(Box::new((Place::return_place(), none_value))),
)];
body.basic_blocks_mut().push(BasicBlockData { body.basic_blocks_mut().push(BasicBlockData {
statements, statements,
@@ -342,10 +342,10 @@ impl<'tcx> TransformVisitor<'tcx> {
} }
}; };
statements.push(Statement { statements.push(Statement::new(
kind: StatementKind::Assign(Box::new((Place::return_place(), rvalue))),
source_info, source_info,
}); StatementKind::Assign(Box::new((Place::return_place(), rvalue))),
));
} }
// Create a Place referencing a coroutine struct field // Create a Place referencing a coroutine struct field
@@ -361,13 +361,13 @@ impl<'tcx> TransformVisitor<'tcx> {
// Create a statement which changes the discriminant // Create a statement which changes the discriminant
fn set_discr(&self, state_disc: VariantIdx, source_info: SourceInfo) -> Statement<'tcx> { fn set_discr(&self, state_disc: VariantIdx, source_info: SourceInfo) -> Statement<'tcx> {
let self_place = Place::from(SELF_ARG); let self_place = Place::from(SELF_ARG);
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::SetDiscriminant { StatementKind::SetDiscriminant {
place: Box::new(self_place), place: Box::new(self_place),
variant_index: state_disc, variant_index: state_disc,
}, },
} )
} }
// Create a statement which reads the discriminant into a temporary // Create a statement which reads the discriminant into a temporary
@@ -377,10 +377,10 @@ impl<'tcx> TransformVisitor<'tcx> {
let temp = Place::from(local_decls_len); let temp = Place::from(local_decls_len);
let self_place = Place::from(SELF_ARG); let self_place = Place::from(SELF_ARG);
let assign = Statement { let assign = Statement::new(
source_info: SourceInfo::outermost(body.span), SourceInfo::outermost(body.span),
kind: StatementKind::Assign(Box::new((temp, Rvalue::Discriminant(self_place)))), StatementKind::Assign(Box::new((temp, Rvalue::Discriminant(self_place)))),
}; );
(assign, temp) (assign, temp)
} }
} }
@@ -450,7 +450,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
&& !self.always_live_locals.contains(l); && !self.always_live_locals.contains(l);
if needs_storage_dead { if needs_storage_dead {
data.statements data.statements
.push(Statement { source_info, kind: StatementKind::StorageDead(l) }); .push(Statement::new(source_info, StatementKind::StorageDead(l)));
} }
} }
@@ -596,10 +596,8 @@ fn eliminate_get_context_call<'tcx>(bb_data: &mut BasicBlockData<'tcx>) -> Local
let local = arg.node.place().unwrap().local; let local = arg.node.place().unwrap().local;
let arg = Rvalue::Use(arg.node); let arg = Rvalue::Use(arg.node);
let assign = Statement { let assign =
source_info: terminator.source_info, Statement::new(terminator.source_info, StatementKind::Assign(Box::new((destination, arg))));
kind: StatementKind::Assign(Box::new((destination, arg))),
};
bb_data.statements.push(assign); bb_data.statements.push(assign);
bb_data.terminator = Some(Terminator { bb_data.terminator = Some(Terminator {
source_info: terminator.source_info, source_info: terminator.source_info,
@@ -1109,10 +1107,7 @@ fn return_poll_ready_assign<'tcx>(tcx: TyCtxt<'tcx>, source_info: SourceInfo) ->
Box::new(AggregateKind::Adt(poll_def_id, VariantIdx::from_usize(0), args, None, None)), Box::new(AggregateKind::Adt(poll_def_id, VariantIdx::from_usize(0), args, None, None)),
IndexVec::from_raw(vec![val]), IndexVec::from_raw(vec![val]),
); );
Statement { Statement::new(source_info, StatementKind::Assign(Box::new((Place::return_place(), ready_val))))
kind: StatementKind::Assign(Box::new((Place::return_place(), ready_val))),
source_info,
}
} }
fn insert_poll_ready_block<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> BasicBlock { fn insert_poll_ready_block<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> BasicBlock {
@@ -1345,21 +1340,20 @@ fn create_cases<'tcx>(
&& !transform.remap.contains(l) && !transform.remap.contains(l)
&& !transform.always_live_locals.contains(l); && !transform.always_live_locals.contains(l);
if needs_storage_live { if needs_storage_live {
statements statements.push(Statement::new(source_info, StatementKind::StorageLive(l)));
.push(Statement { source_info, kind: StatementKind::StorageLive(l) });
} }
} }
if operation == Operation::Resume { if operation == Operation::Resume {
// Move the resume argument to the destination place of the `Yield` terminator // Move the resume argument to the destination place of the `Yield` terminator
let resume_arg = CTX_ARG; let resume_arg = CTX_ARG;
statements.push(Statement { statements.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
point.resume_arg, point.resume_arg,
Rvalue::Use(Operand::Move(resume_arg.into())), Rvalue::Use(Operand::Move(resume_arg.into())),
))), ))),
}); ));
} }
// Then jump to the real target // Then jump to the real target
@@ -1540,13 +1534,13 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
let stmts = &mut body.basic_blocks_mut()[START_BLOCK].statements; let stmts = &mut body.basic_blocks_mut()[START_BLOCK].statements;
stmts.insert( stmts.insert(
0, 0,
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
old_resume_local.into(), old_resume_local.into(),
Rvalue::Use(Operand::Move(resume_local.into())), Rvalue::Use(Operand::Move(resume_local.into())),
))), ))),
}, ),
); );
let always_live_locals = always_storage_live_locals(body); let always_live_locals = always_storage_live_locals(body);

View File

@@ -87,12 +87,11 @@ fn build_pin_fut<'tcx>(
const_: Const::zero_sized(pin_fut_new_unchecked_fn), const_: Const::zero_sized(pin_fut_new_unchecked_fn),
})); }));
let storage_live = let storage_live = Statement::new(source_info, StatementKind::StorageLive(fut_pin_place.local));
Statement { source_info, kind: StatementKind::StorageLive(fut_pin_place.local) };
let fut_ref_assign = Statement { let fut_ref_assign = Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
fut_ref_place, fut_ref_place,
Rvalue::Ref( Rvalue::Ref(
tcx.lifetimes.re_erased, tcx.lifetimes.re_erased,
@@ -100,7 +99,7 @@ fn build_pin_fut<'tcx>(
fut_place, fut_place,
), ),
))), ))),
}; );
// call Pin<FutTy>::new_unchecked(&mut fut) // call Pin<FutTy>::new_unchecked(&mut fut)
let pin_fut_bb = body.basic_blocks_mut().push(BasicBlockData { let pin_fut_bb = body.basic_blocks_mut().push(BasicBlockData {
@@ -156,15 +155,11 @@ fn build_poll_switch<'tcx>(
let source_info = SourceInfo::outermost(body.span); let source_info = SourceInfo::outermost(body.span);
let poll_discr_place = let poll_discr_place =
Place::from(body.local_decls.push(LocalDecl::new(poll_discr_ty, source_info.span))); Place::from(body.local_decls.push(LocalDecl::new(poll_discr_ty, source_info.span)));
let discr_assign = Statement { let discr_assign = Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((poll_discr_place, Rvalue::Discriminant(*poll_unit_place)))),
poll_discr_place, );
Rvalue::Discriminant(*poll_unit_place), let storage_dead = Statement::new(source_info, StatementKind::StorageDead(fut_pin_place.local));
))),
};
let storage_dead =
Statement { source_info, kind: StatementKind::StorageDead(fut_pin_place.local) };
let unreachable_block = insert_term_block(body, TerminatorKind::Unreachable); let unreachable_block = insert_term_block(body, TerminatorKind::Unreachable);
body.basic_blocks_mut().push(BasicBlockData { body.basic_blocks_mut().push(BasicBlockData {
statements: [storage_dead, discr_assign].to_vec(), statements: [storage_dead, discr_assign].to_vec(),
@@ -330,10 +325,10 @@ pub(super) fn expand_async_drops<'tcx>(
let context_ref_place = let context_ref_place =
Place::from(body.local_decls.push(LocalDecl::new(context_mut_ref, source_info.span))); Place::from(body.local_decls.push(LocalDecl::new(context_mut_ref, source_info.span)));
let arg = Rvalue::Use(Operand::Move(Place::from(CTX_ARG))); let arg = Rvalue::Use(Operand::Move(Place::from(CTX_ARG)));
body[bb].statements.push(Statement { body[bb].statements.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new((context_ref_place, arg))), StatementKind::Assign(Box::new((context_ref_place, arg))),
}); ));
let yield_block = insert_term_block(body, TerminatorKind::Unreachable); // `kind` replaced later to yield let yield_block = insert_term_block(body, TerminatorKind::Unreachable); // `kind` replaced later to yield
let (pin_bb, fut_pin_place) = let (pin_bb, fut_pin_place) =
build_pin_fut(tcx, body, fut_place.clone(), UnwindAction::Continue); build_pin_fut(tcx, body, fut_place.clone(), UnwindAction::Continue);

View File

@@ -259,7 +259,7 @@ fn inject_statement(mir_body: &mut mir::Body<'_>, counter_kind: CoverageKind, bb
debug!(" injecting statement {counter_kind:?} for {bb:?}"); debug!(" injecting statement {counter_kind:?} for {bb:?}");
let data = &mut mir_body[bb]; let data = &mut mir_body[bb];
let source_info = data.terminator().source_info; let source_info = data.terminator().source_info;
let statement = Statement { source_info, kind: StatementKind::Coverage(counter_kind) }; let statement = Statement::new(source_info, StatementKind::Coverage(counter_kind));
data.statements.insert(0, statement); data.statements.insert(0, statement);
} }

View File

@@ -55,8 +55,8 @@ fn has_back_edge(
} }
fn insert_counter(basic_block_data: &mut BasicBlockData<'_>) { fn insert_counter(basic_block_data: &mut BasicBlockData<'_>) {
basic_block_data.statements.push(Statement { basic_block_data.statements.push(Statement::new(
source_info: basic_block_data.terminator().source_info, basic_block_data.terminator().source_info,
kind: StatementKind::ConstEvalCounter, StatementKind::ConstEvalCounter,
}); ));
} }

View File

@@ -366,10 +366,8 @@ where
call_statements.push(self.assign(obj_ptr_place, addr)); call_statements.push(self.assign(obj_ptr_place, addr));
obj_ptr_place obj_ptr_place
}; };
call_statements.push(Statement { call_statements
source_info: self.source_info, .push(Statement::new(self.source_info, StatementKind::StorageLive(fut.local)));
kind: StatementKind::StorageLive(fut.local),
});
let call_drop_bb = self.new_block_with_statements( let call_drop_bb = self.new_block_with_statements(
unwind, unwind,
@@ -1467,9 +1465,6 @@ where
} }
fn assign(&self, lhs: Place<'tcx>, rhs: Rvalue<'tcx>) -> Statement<'tcx> { fn assign(&self, lhs: Place<'tcx>, rhs: Rvalue<'tcx>) -> Statement<'tcx> {
Statement { Statement::new(self.source_info, StatementKind::Assign(Box::new((lhs, rhs))))
source_info: self.source_info,
kind: StatementKind::Assign(Box::new((lhs, rhs))),
}
} }
} }

View File

@@ -900,10 +900,10 @@ fn inline_call<'tcx, I: Inliner<'tcx>>(
); );
let dest_ty = dest.ty(caller_body, tcx); let dest_ty = dest.ty(caller_body, tcx);
let temp = Place::from(new_call_temp(caller_body, callsite, dest_ty, return_block)); let temp = Place::from(new_call_temp(caller_body, callsite, dest_ty, return_block));
caller_body[callsite.block].statements.push(Statement { caller_body[callsite.block].statements.push(Statement::new(
source_info: callsite.source_info, callsite.source_info,
kind: StatementKind::Assign(Box::new((temp, dest))), StatementKind::Assign(Box::new((temp, dest))),
}); ));
tcx.mk_place_deref(temp) tcx.mk_place_deref(temp)
} else { } else {
destination destination
@@ -947,10 +947,9 @@ fn inline_call<'tcx, I: Inliner<'tcx>>(
for local in callee_body.vars_and_temps_iter() { for local in callee_body.vars_and_temps_iter() {
if integrator.always_live_locals.contains(local) { if integrator.always_live_locals.contains(local) {
let new_local = integrator.map_local(local); let new_local = integrator.map_local(local);
caller_body[callsite.block].statements.push(Statement { caller_body[callsite.block]
source_info: callsite.source_info, .statements
kind: StatementKind::StorageLive(new_local), .push(Statement::new(callsite.source_info, StatementKind::StorageLive(new_local)));
});
} }
} }
if let Some(block) = return_block { if let Some(block) = return_block {
@@ -958,22 +957,22 @@ fn inline_call<'tcx, I: Inliner<'tcx>>(
// the slice once. // the slice once.
let mut n = 0; let mut n = 0;
if remap_destination { if remap_destination {
caller_body[block].statements.push(Statement { caller_body[block].statements.push(Statement::new(
source_info: callsite.source_info, callsite.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
dest, dest,
Rvalue::Use(Operand::Move(destination_local.into())), Rvalue::Use(Operand::Move(destination_local.into())),
))), ))),
}); ));
n += 1; n += 1;
} }
for local in callee_body.vars_and_temps_iter().rev() { for local in callee_body.vars_and_temps_iter().rev() {
if integrator.always_live_locals.contains(local) { if integrator.always_live_locals.contains(local) {
let new_local = integrator.map_local(local); let new_local = integrator.map_local(local);
caller_body[block].statements.push(Statement { caller_body[block].statements.push(Statement::new(
source_info: callsite.source_info, callsite.source_info,
kind: StatementKind::StorageDead(new_local), StatementKind::StorageDead(new_local),
}); ));
n += 1; n += 1;
} }
} }
@@ -1126,10 +1125,10 @@ fn create_temp_if_necessary<'tcx, I: Inliner<'tcx>>(
trace!("creating temp for argument {:?}", arg); trace!("creating temp for argument {:?}", arg);
let arg_ty = arg.ty(caller_body, inliner.tcx()); let arg_ty = arg.ty(caller_body, inliner.tcx());
let local = new_call_temp(caller_body, callsite, arg_ty, return_block); let local = new_call_temp(caller_body, callsite, arg_ty, return_block);
caller_body[callsite.block].statements.push(Statement { caller_body[callsite.block].statements.push(Statement::new(
source_info: callsite.source_info, callsite.source_info,
kind: StatementKind::Assign(Box::new((Place::from(local), Rvalue::Use(arg)))), StatementKind::Assign(Box::new((Place::from(local), Rvalue::Use(arg)))),
}); ));
local local
} }
@@ -1142,19 +1141,14 @@ fn new_call_temp<'tcx>(
) -> Local { ) -> Local {
let local = caller_body.local_decls.push(LocalDecl::new(ty, callsite.source_info.span)); let local = caller_body.local_decls.push(LocalDecl::new(ty, callsite.source_info.span));
caller_body[callsite.block].statements.push(Statement { caller_body[callsite.block]
source_info: callsite.source_info, .statements
kind: StatementKind::StorageLive(local), .push(Statement::new(callsite.source_info, StatementKind::StorageLive(local)));
});
if let Some(block) = return_block { if let Some(block) = return_block {
caller_body[block].statements.insert( caller_body[block]
0, .statements
Statement { .insert(0, Statement::new(callsite.source_info, StatementKind::StorageDead(local)));
source_info: callsite.source_info,
kind: StatementKind::StorageDead(local),
},
);
} }
local local

View File

@@ -240,15 +240,15 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
let Some(arg_place) = arg.node.place() else { return }; let Some(arg_place) = arg.node.place() else { return };
statements.push(Statement { statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::Use(Operand::Copy( Rvalue::Use(Operand::Copy(
arg_place.project_deeper(&[ProjectionElem::Deref], self.tcx), arg_place.project_deeper(&[ProjectionElem::Deref], self.tcx),
)), )),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target: *destination_block }; terminator.kind = TerminatorKind::Goto { target: *destination_block };
} }

View File

@@ -259,13 +259,13 @@ fn remap_mir_for_const_eval_select<'tcx>(
// (const generic stuff) so we just create a temporary and deconstruct // (const generic stuff) so we just create a temporary and deconstruct
// that. // that.
let local = body.local_decls.push(LocalDecl::new(ty, fn_span)); let local = body.local_decls.push(LocalDecl::new(ty, fn_span));
bb.statements.push(Statement { bb.statements.push(Statement::new(
source_info: SourceInfo::outermost(fn_span), SourceInfo::outermost(fn_span),
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
local.into(), local.into(),
Rvalue::Use(tupled_args.node.clone()), Rvalue::Use(tupled_args.node.clone()),
))), ))),
}); ));
(Operand::Move, local.into()) (Operand::Move, local.into())
} }
Operand::Move(place) => (Operand::Move, place), Operand::Move(place) => (Operand::Move, place),

View File

@@ -25,31 +25,31 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
} }
sym::ub_checks => { sym::ub_checks => {
let target = target.unwrap(); let target = target.unwrap();
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::NullaryOp(NullOp::UbChecks, tcx.types.bool), Rvalue::NullaryOp(NullOp::UbChecks, tcx.types.bool),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::contract_checks => { sym::contract_checks => {
let target = target.unwrap(); let target = target.unwrap();
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::NullaryOp(NullOp::ContractChecks, tcx.types.bool), Rvalue::NullaryOp(NullOp::ContractChecks, tcx.types.bool),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::forget => { sym::forget => {
let target = target.unwrap(); let target = target.unwrap();
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::Use(Operand::Constant(Box::new(ConstOperand { Rvalue::Use(Operand::Constant(Box::new(ConstOperand {
span: terminator.source_info.span, span: terminator.source_info.span,
@@ -57,7 +57,7 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
const_: Const::zero_sized(tcx.types.unit), const_: Const::zero_sized(tcx.types.unit),
}))), }))),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::copy_nonoverlapping => { sym::copy_nonoverlapping => {
@@ -65,9 +65,9 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
let Ok([src, dst, count]) = take_array(args) else { let Ok([src, dst, count]) = take_array(args) else {
bug!("Wrong arguments for copy_non_overlapping intrinsic"); bug!("Wrong arguments for copy_non_overlapping intrinsic");
}; };
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Intrinsic(Box::new( StatementKind::Intrinsic(Box::new(
NonDivergingIntrinsic::CopyNonOverlapping( NonDivergingIntrinsic::CopyNonOverlapping(
rustc_middle::mir::CopyNonOverlapping { rustc_middle::mir::CopyNonOverlapping {
src: src.node, src: src.node,
@@ -76,7 +76,7 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
}, },
), ),
)), )),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::assume => { sym::assume => {
@@ -84,12 +84,12 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
let Ok([arg]) = take_array(args) else { let Ok([arg]) = take_array(args) else {
bug!("Wrong arguments for assume intrinsic"); bug!("Wrong arguments for assume intrinsic");
}; };
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Intrinsic(Box::new( StatementKind::Intrinsic(Box::new(NonDivergingIntrinsic::Assume(
NonDivergingIntrinsic::Assume(arg.node), arg.node,
)), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::wrapping_add sym::wrapping_add
@@ -121,13 +121,13 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
sym::unchecked_shr => BinOp::ShrUnchecked, sym::unchecked_shr => BinOp::ShrUnchecked,
_ => bug!("unexpected intrinsic"), _ => bug!("unexpected intrinsic"),
}; };
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::BinaryOp(bin_op, Box::new((lhs.node, rhs.node))), Rvalue::BinaryOp(bin_op, Box::new((lhs.node, rhs.node))),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => { sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
@@ -141,13 +141,13 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
sym::mul_with_overflow => BinOp::MulWithOverflow, sym::mul_with_overflow => BinOp::MulWithOverflow,
_ => bug!("unexpected intrinsic"), _ => bug!("unexpected intrinsic"),
}; };
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::BinaryOp(bin_op, Box::new((lhs.node, rhs.node))), Rvalue::BinaryOp(bin_op, Box::new((lhs.node, rhs.node))),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::size_of | sym::align_of => { sym::size_of | sym::align_of => {
@@ -158,13 +158,13 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
sym::align_of => NullOp::AlignOf, sym::align_of => NullOp::AlignOf,
_ => bug!("unexpected intrinsic"), _ => bug!("unexpected intrinsic"),
}; };
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::NullaryOp(null_op, tp_ty), Rvalue::NullaryOp(null_op, tp_ty),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::read_via_copy => { sym::read_via_copy => {
@@ -183,13 +183,13 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
}; };
// Add new statement at the end of the block that does the read, and patch // Add new statement at the end of the block that does the read, and patch
// up the terminator. // up the terminator.
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::Use(Operand::Copy(derefed_place)), Rvalue::Use(Operand::Copy(derefed_place)),
))), ))),
}); ));
terminator.kind = match *target { terminator.kind = match *target {
None => { None => {
// No target means this read something uninhabited, // No target means this read something uninhabited,
@@ -217,13 +217,10 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
"Only passing a local is supported" "Only passing a local is supported"
); );
}; };
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((derefed_place, Rvalue::Use(val.node)))),
derefed_place, ));
Rvalue::Use(val.node),
))),
});
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::discriminant_value => { sym::discriminant_value => {
@@ -236,13 +233,13 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
}; };
let arg = arg.node.place().unwrap(); let arg = arg.node.place().unwrap();
let arg = tcx.mk_place_deref(arg); let arg = tcx.mk_place_deref(arg);
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::Discriminant(arg), Rvalue::Discriminant(arg),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::offset => { sym::offset => {
@@ -253,13 +250,13 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
"Wrong number of arguments for offset intrinsic", "Wrong number of arguments for offset intrinsic",
); );
}; };
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::BinaryOp(BinOp::Offset, Box::new((ptr.node, delta.node))), Rvalue::BinaryOp(BinOp::Offset, Box::new((ptr.node, delta.node))),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::slice_get_unchecked => { sym::slice_get_unchecked => {
@@ -302,10 +299,10 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
_ => bug!("Unknown return type {ret_ty:?}"), _ => bug!("Unknown return type {ret_ty:?}"),
}; };
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new((*destination, rvalue))), StatementKind::Assign(Box::new((*destination, rvalue))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::transmute | sym::transmute_unchecked => { sym::transmute | sym::transmute_unchecked => {
@@ -320,13 +317,13 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
// Always emit the cast, even if we transmute to an uninhabited type, // Always emit the cast, even if we transmute to an uninhabited type,
// because that lets CTFE and codegen generate better error messages // because that lets CTFE and codegen generate better error messages
// when such a transmute actually ends up reachable. // when such a transmute actually ends up reachable.
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::Cast(CastKind::Transmute, arg.node, dst_ty), Rvalue::Cast(CastKind::Transmute, arg.node, dst_ty),
))), ))),
}); ));
if let Some(target) = *target { if let Some(target) = *target {
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} else { } else {
@@ -351,13 +348,13 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
); );
}; };
let fields = [data.node, meta.node]; let fields = [data.node, meta.node];
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::Aggregate(Box::new(kind), fields.into()), Rvalue::Aggregate(Box::new(kind), fields.into()),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
sym::ptr_metadata => { sym::ptr_metadata => {
@@ -368,13 +365,13 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
); );
}; };
let target = target.unwrap(); let target = target.unwrap();
block.statements.push(Statement { block.statements.push(Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
*destination, *destination,
Rvalue::UnaryOp(UnOp::PtrMetadata, ptr.node), Rvalue::UnaryOp(UnOp::PtrMetadata, ptr.node),
))), ))),
}); ));
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };
} }
_ => {} _ => {}

View File

@@ -56,8 +56,7 @@ fn lower_slice_len_call<'tcx>(block: &mut BasicBlockData<'tcx>, slice_len_fn_ite
// make new RValue for Len // make new RValue for Len
let r_value = Rvalue::UnaryOp(UnOp::PtrMetadata, arg.node.clone()); let r_value = Rvalue::UnaryOp(UnOp::PtrMetadata, arg.node.clone());
let len_statement_kind = StatementKind::Assign(Box::new((*destination, r_value))); let len_statement_kind = StatementKind::Assign(Box::new((*destination, r_value)));
let add_statement = let add_statement = Statement::new(terminator.source_info, len_statement_kind);
Statement { kind: len_statement_kind, source_info: terminator.source_info };
// modify terminator into simple Goto // modify terminator into simple Goto
let new_terminator_kind = TerminatorKind::Goto { target: *bb }; let new_terminator_kind = TerminatorKind::Goto { target: *bb };

View File

@@ -280,7 +280,7 @@ impl<'tcx> MirPatch<'tcx> {
let source_info = Self::source_info_for_index(&body[loc.block], loc); let source_info = Self::source_info_for_index(&body[loc.block], loc);
body[loc.block] body[loc.block]
.statements .statements
.insert(loc.statement_index, Statement { source_info, kind: stmt }); .insert(loc.statement_index, Statement::new(source_info, stmt));
delta += 1; delta += 1;
} }
} }

View File

@@ -744,10 +744,10 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
fn assign(&mut self, dest: Local, rvalue: Rvalue<'tcx>, span: Span) { fn assign(&mut self, dest: Local, rvalue: Rvalue<'tcx>, span: Span) {
let last = self.promoted.basic_blocks.last_index().unwrap(); let last = self.promoted.basic_blocks.last_index().unwrap();
let data = &mut self.promoted[last]; let data = &mut self.promoted[last];
data.statements.push(Statement { data.statements.push(Statement::new(
source_info: SourceInfo::outermost(span), SourceInfo::outermost(span),
kind: StatementKind::Assign(Box::new((Place::from(dest), rvalue))), StatementKind::Assign(Box::new((Place::from(dest), rvalue))),
}); ));
} }
fn is_temp_kind(&self, local: Local) -> bool { fn is_temp_kind(&self, local: Local) -> bool {
@@ -914,13 +914,13 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref); assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref);
let promoted_operand = promoted_operand(ref_ty, span); let promoted_operand = promoted_operand(ref_ty, span);
let promoted_ref_statement = Statement { let promoted_ref_statement = Statement::new(
source_info: statement.source_info, statement.source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
Place::from(promoted_ref), Place::from(promoted_ref),
Rvalue::Use(Operand::Constant(Box::new(promoted_operand))), Rvalue::Use(Operand::Constant(Box::new(promoted_operand))),
))), ))),
}; );
self.extra_statements.push((loc, promoted_ref_statement)); self.extra_statements.push((loc, promoted_ref_statement));
( (

View File

@@ -323,9 +323,7 @@ fn dropee_emit_retag<'tcx>(
StatementKind::Retag(RetagKind::FnEntry, Box::new(dropee_ptr)), StatementKind::Retag(RetagKind::FnEntry, Box::new(dropee_ptr)),
]; ];
for s in new_statements { for s in new_statements {
body.basic_blocks_mut()[START_BLOCK] body.basic_blocks_mut()[START_BLOCK].statements.push(Statement::new(source_info, s));
.statements
.push(Statement { source_info, kind: s });
} }
} }
dropee_ptr dropee_ptr
@@ -516,13 +514,13 @@ fn build_thread_local_shim<'tcx>(
let source_info = SourceInfo::outermost(span); let source_info = SourceInfo::outermost(span);
let blocks = IndexVec::from_raw(vec![BasicBlockData { let blocks = IndexVec::from_raw(vec![BasicBlockData {
statements: vec![Statement { statements: vec![Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
Place::return_place(), Place::return_place(),
Rvalue::ThreadLocalRef(def_id), Rvalue::ThreadLocalRef(def_id),
))), ))),
}], )],
terminator: Some(Terminator { source_info, kind: TerminatorKind::Return }), terminator: Some(Terminator { source_info, kind: TerminatorKind::Return }),
is_cleanup: false, is_cleanup: false,
}]); }]);
@@ -625,7 +623,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
} }
fn make_statement(&self, kind: StatementKind<'tcx>) -> Statement<'tcx> { fn make_statement(&self, kind: StatementKind<'tcx>) -> Statement<'tcx> {
Statement { source_info: self.source_info(), kind } Statement::new(self.source_info(), kind)
} }
fn copy_shim(&mut self) { fn copy_shim(&mut self) {
@@ -901,13 +899,13 @@ fn build_call_shim<'tcx>(
.immutable(), .immutable(),
); );
let borrow_kind = BorrowKind::Mut { kind: MutBorrowKind::Default }; let borrow_kind = BorrowKind::Mut { kind: MutBorrowKind::Default };
statements.push(Statement { statements.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
Place::from(ref_rcvr), Place::from(ref_rcvr),
Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_place()), Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_place()),
))), ))),
}); ));
Operand::Move(Place::from(ref_rcvr)) Operand::Move(Place::from(ref_rcvr))
} }
}); });
@@ -1071,8 +1069,9 @@ pub(super) fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
let kind = AggregateKind::Adt(adt_def.did(), variant_index, args, None, None); let kind = AggregateKind::Adt(adt_def.did(), variant_index, args, None, None);
let variant = adt_def.variant(variant_index); let variant = adt_def.variant(variant_index);
let statement = Statement { let statement = Statement::new(
kind: StatementKind::Assign(Box::new(( source_info,
StatementKind::Assign(Box::new((
Place::return_place(), Place::return_place(),
Rvalue::Aggregate( Rvalue::Aggregate(
Box::new(kind), Box::new(kind),
@@ -1081,8 +1080,7 @@ pub(super) fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
.collect(), .collect(),
), ),
))), ))),
source_info, );
};
let start_block = BasicBlockData { let start_block = BasicBlockData {
statements: vec![statement], statements: vec![statement],
@@ -1130,10 +1128,10 @@ fn build_fn_ptr_addr_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'t
Operand::Move(Place::from(Local::new(1))), Operand::Move(Place::from(Local::new(1))),
Ty::new_imm_ptr(tcx, tcx.types.unit), Ty::new_imm_ptr(tcx, tcx.types.unit),
); );
let stmt = Statement { let stmt = Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new((Place::return_place(), rvalue))), StatementKind::Assign(Box::new((Place::return_place(), rvalue))),
}; );
let statements = vec![stmt]; let statements = vec![stmt];
let start_block = BasicBlockData { let start_block = BasicBlockData {
statements, statements,
@@ -1230,10 +1228,10 @@ fn build_construct_coroutine_by_move_shim<'tcx>(
Box::new(AggregateKind::Coroutine(coroutine_def_id, coroutine_args)), Box::new(AggregateKind::Coroutine(coroutine_def_id, coroutine_args)),
IndexVec::from_raw(fields), IndexVec::from_raw(fields),
); );
let stmt = Statement { let stmt = Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new((Place::return_place(), rvalue))), StatementKind::Assign(Box::new((Place::return_place(), rvalue))),
}; );
let statements = vec![stmt]; let statements = vec![stmt];
let start_block = BasicBlockData { let start_block = BasicBlockData {
statements, statements,

View File

@@ -133,7 +133,7 @@ pub(super) fn build_async_drop_shim<'tcx>(
dropee_ptr, dropee_ptr,
Rvalue::Use(Operand::Move(coroutine_layout_dropee)), Rvalue::Use(Operand::Move(coroutine_layout_dropee)),
))); )));
body.basic_blocks_mut()[START_BLOCK].statements.push(Statement { source_info, kind: st_kind }); body.basic_blocks_mut()[START_BLOCK].statements.push(Statement::new(source_info, st_kind));
dropee_ptr = dropee_emit_retag(tcx, &mut body, dropee_ptr, span); dropee_ptr = dropee_emit_retag(tcx, &mut body, dropee_ptr, span);
let dropline = body.basic_blocks.last_index(); let dropline = body.basic_blocks.last_index();
@@ -240,13 +240,13 @@ fn build_adrop_for_coroutine_shim<'tcx>(
.project_deeper(&[PlaceElem::Field(FieldIdx::ZERO, proxy_ref)], tcx); .project_deeper(&[PlaceElem::Field(FieldIdx::ZERO, proxy_ref)], tcx);
body.basic_blocks_mut()[START_BLOCK].statements.insert( body.basic_blocks_mut()[START_BLOCK].statements.insert(
idx, idx,
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
Place::from(proxy_ref_local), Place::from(proxy_ref_local),
Rvalue::CopyForDeref(proxy_ref_place), Rvalue::CopyForDeref(proxy_ref_place),
))), ))),
}, ),
); );
idx += 1; idx += 1;
let mut cor_ptr_local = proxy_ref_local; let mut cor_ptr_local = proxy_ref_local;
@@ -261,13 +261,13 @@ fn build_adrop_for_coroutine_shim<'tcx>(
// _cor_ptr = _proxy.0.0 (... .0) // _cor_ptr = _proxy.0.0 (... .0)
body.basic_blocks_mut()[START_BLOCK].statements.insert( body.basic_blocks_mut()[START_BLOCK].statements.insert(
idx, idx,
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
Place::from(cor_ptr_local), Place::from(cor_ptr_local),
Rvalue::CopyForDeref(impl_ptr_place), Rvalue::CopyForDeref(impl_ptr_place),
))), ))),
}, ),
); );
idx += 1; idx += 1;
} }
@@ -281,10 +281,10 @@ fn build_adrop_for_coroutine_shim<'tcx>(
); );
body.basic_blocks_mut()[START_BLOCK].statements.insert( body.basic_blocks_mut()[START_BLOCK].statements.insert(
idx, idx,
Statement { Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new((Place::from(cor_ref_local), reborrow))), StatementKind::Assign(Box::new((Place::from(cor_ref_local), reborrow))),
}, ),
); );
} }
body body
@@ -334,13 +334,13 @@ fn build_adrop_for_adrop_shim<'tcx>(
let mut statements = Vec::new(); let mut statements = Vec::new();
statements.push(Statement { statements.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
Place::from(proxy_ref_local), Place::from(proxy_ref_local),
Rvalue::CopyForDeref(proxy_ref_place), Rvalue::CopyForDeref(proxy_ref_place),
))), ))),
}); ));
let mut cor_ptr_local = proxy_ref_local; let mut cor_ptr_local = proxy_ref_local;
proxy_ty.find_async_drop_impl_coroutine(tcx, |ty| { proxy_ty.find_async_drop_impl_coroutine(tcx, |ty| {
@@ -350,13 +350,13 @@ fn build_adrop_for_adrop_shim<'tcx>(
.project_deeper(&[PlaceElem::Deref, PlaceElem::Field(FieldIdx::ZERO, ty_ptr)], tcx); .project_deeper(&[PlaceElem::Deref, PlaceElem::Field(FieldIdx::ZERO, ty_ptr)], tcx);
cor_ptr_local = locals.push(LocalDecl::new(ty_ptr, span)); cor_ptr_local = locals.push(LocalDecl::new(ty_ptr, span));
// _cor_ptr = _proxy.0.0 (... .0) // _cor_ptr = _proxy.0.0 (... .0)
statements.push(Statement { statements.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new(( StatementKind::Assign(Box::new((
Place::from(cor_ptr_local), Place::from(cor_ptr_local),
Rvalue::CopyForDeref(impl_ptr_place), Rvalue::CopyForDeref(impl_ptr_place),
))), ))),
}); ));
} }
}); });
@@ -367,10 +367,10 @@ fn build_adrop_for_adrop_shim<'tcx>(
tcx.mk_place_deref(Place::from(cor_ptr_local)), tcx.mk_place_deref(Place::from(cor_ptr_local)),
); );
let cor_ref_place = Place::from(locals.push(LocalDecl::new(cor_ref, span))); let cor_ref_place = Place::from(locals.push(LocalDecl::new(cor_ref, span)));
statements.push(Statement { statements.push(Statement::new(
source_info, source_info,
kind: StatementKind::Assign(Box::new((cor_ref_place, reborrow))), StatementKind::Assign(Box::new((cor_ref_place, reborrow))),
}); ));
// cor_pin_ty = `Pin<&mut cor_ref>` // cor_pin_ty = `Pin<&mut cor_ref>`
let cor_pin_ty = Ty::new_adt(tcx, pin_adt_ref, tcx.mk_args(&[cor_ref.into()])); let cor_pin_ty = Ty::new_adt(tcx, pin_adt_ref, tcx.mk_args(&[cor_ref.into()]));

View File

@@ -115,10 +115,10 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyComparisonIntegral {
for bb_idx in new_targets.all_targets() { for bb_idx in new_targets.all_targets() {
storage_deads_to_insert.push(( storage_deads_to_insert.push((
*bb_idx, *bb_idx,
Statement { Statement::new(
source_info: terminator.source_info, terminator.source_info,
kind: StatementKind::StorageDead(opt.to_switch_on.local), StatementKind::StorageDead(opt.to_switch_on.local),
}, ),
)); ));
} }
} }