Skip to content

Commit 2a8513d

Browse files
committed
Replace visitor with a loop over blocks and statements
1 parent aef17b7 commit 2a8513d

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,28 @@
1919
//! [`Nop`]: rustc_middle::mir::StatementKind::Nop
2020
2121
use crate::MirPass;
22-
use rustc_middle::mir::visit::MutVisitor;
23-
use rustc_middle::mir::{Body, BorrowKind, Location, Rvalue};
24-
use rustc_middle::mir::{Statement, StatementKind};
22+
use rustc_middle::mir::{Body, BorrowKind, Rvalue, StatementKind};
2523
use rustc_middle::ty::TyCtxt;
2624

2725
pub struct CleanupNonCodegenStatements;
2826

29-
pub struct DeleteNonCodegenStatements<'tcx> {
30-
tcx: TyCtxt<'tcx>,
31-
}
32-
3327
impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements {
34-
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
35-
let mut delete = DeleteNonCodegenStatements { tcx };
36-
delete.visit_body_preserves_cfg(body);
28+
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
29+
for basic_block in body.basic_blocks.as_mut_preserves_cfg() {
30+
for statement in basic_block.statements.iter_mut() {
31+
match statement.kind {
32+
StatementKind::AscribeUserType(..)
33+
| StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Shallow, _)))
34+
| StatementKind::FakeRead(..) => statement.make_nop(),
35+
_ => (),
36+
}
37+
}
38+
}
39+
3740
body.user_type_annotations.raw.clear();
3841

3942
for decl in &mut body.local_decls {
4043
decl.user_ty = None;
4144
}
4245
}
4346
}
44-
45-
impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements<'tcx> {
46-
fn tcx(&self) -> TyCtxt<'tcx> {
47-
self.tcx
48-
}
49-
50-
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
51-
match statement.kind {
52-
StatementKind::AscribeUserType(..)
53-
| StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Shallow, _)))
54-
| StatementKind::FakeRead(..) => statement.make_nop(),
55-
_ => (),
56-
}
57-
self.super_statement(statement, location);
58-
}
59-
}

0 commit comments

Comments
 (0)