Inline and replace Statement::replace_nop
.
It has a single call site, and doesn't seem worth having as an API function.
This commit is contained in:
parent
69f5e342bf
commit
04eeda47ab
3 changed files with 6 additions and 13 deletions
|
@ -4,8 +4,8 @@
|
|||
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::{self, Debug, Formatter};
|
||||
use std::iter;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::{iter, mem};
|
||||
|
||||
pub use basic_blocks::BasicBlocks;
|
||||
use either::Either;
|
||||
|
|
|
@ -19,15 +19,6 @@ impl Statement<'_> {
|
|||
pub fn make_nop(&mut self) {
|
||||
self.kind = StatementKind::Nop
|
||||
}
|
||||
|
||||
/// Changes a statement to a nop and returns the original statement.
|
||||
#[must_use = "If you don't need the statement, use `make_nop` instead"]
|
||||
pub fn replace_nop(&mut self) -> Self {
|
||||
Statement {
|
||||
source_info: self.source_info,
|
||||
kind: mem::replace(&mut self.kind, StatementKind::Nop),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> StatementKind<'tcx> {
|
||||
|
|
|
@ -48,9 +48,11 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts {
|
|||
|
||||
// We're only changing an operand, not the terminator kinds or successors
|
||||
let basic_blocks = body.basic_blocks.as_mut_preserves_cfg();
|
||||
let init_statement =
|
||||
basic_blocks[init_loc.block].statements[init_loc.statement_index].replace_nop();
|
||||
let StatementKind::Assign(place_and_rvalue) = init_statement.kind else {
|
||||
let init_statement_kind = std::mem::replace(
|
||||
&mut basic_blocks[init_loc.block].statements[init_loc.statement_index].kind,
|
||||
StatementKind::Nop,
|
||||
);
|
||||
let StatementKind::Assign(place_and_rvalue) = init_statement_kind else {
|
||||
bug!("No longer an assign?");
|
||||
};
|
||||
let (place, rvalue) = *place_and_rvalue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue