Skip to content

Commit 04eeda4

Browse files
committed
Inline and replace Statement::replace_nop.
It has a single call site, and doesn't seem worth having as an API function.
1 parent 69f5e34 commit 04eeda4

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
55
use std::borrow::Cow;
66
use std::fmt::{self, Debug, Formatter};
7+
use std::iter;
78
use std::ops::{Index, IndexMut};
8-
use std::{iter, mem};
99

1010
pub use basic_blocks::BasicBlocks;
1111
use either::Either;

compiler/rustc_middle/src/mir/statement.rs

-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ impl Statement<'_> {
1919
pub fn make_nop(&mut self) {
2020
self.kind = StatementKind::Nop
2121
}
22-
23-
/// Changes a statement to a nop and returns the original statement.
24-
#[must_use = "If you don't need the statement, use `make_nop` instead"]
25-
pub fn replace_nop(&mut self) -> Self {
26-
Statement {
27-
source_info: self.source_info,
28-
kind: mem::replace(&mut self.kind, StatementKind::Nop),
29-
}
30-
}
3122
}
3223

3324
impl<'tcx> StatementKind<'tcx> {

compiler/rustc_mir_transform/src/single_use_consts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts {
4848

4949
// We're only changing an operand, not the terminator kinds or successors
5050
let basic_blocks = body.basic_blocks.as_mut_preserves_cfg();
51-
let init_statement =
52-
basic_blocks[init_loc.block].statements[init_loc.statement_index].replace_nop();
53-
let StatementKind::Assign(place_and_rvalue) = init_statement.kind else {
51+
let init_statement_kind = std::mem::replace(
52+
&mut basic_blocks[init_loc.block].statements[init_loc.statement_index].kind,
53+
StatementKind::Nop,
54+
);
55+
let StatementKind::Assign(place_and_rvalue) = init_statement_kind else {
5456
bug!("No longer an assign?");
5557
};
5658
let (place, rvalue) = *place_and_rvalue;

0 commit comments

Comments
 (0)