Replace visitor with a loop over blocks and statements
This commit is contained in:
parent
aef17b7ae6
commit
2a8513d221
1 changed files with 13 additions and 26 deletions
|
@ -19,21 +19,24 @@
|
||||||
//! [`Nop`]: rustc_middle::mir::StatementKind::Nop
|
//! [`Nop`]: rustc_middle::mir::StatementKind::Nop
|
||||||
|
|
||||||
use crate::MirPass;
|
use crate::MirPass;
|
||||||
use rustc_middle::mir::visit::MutVisitor;
|
use rustc_middle::mir::{Body, BorrowKind, Rvalue, StatementKind};
|
||||||
use rustc_middle::mir::{Body, BorrowKind, Location, Rvalue};
|
|
||||||
use rustc_middle::mir::{Statement, StatementKind};
|
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
|
||||||
pub struct CleanupNonCodegenStatements;
|
pub struct CleanupNonCodegenStatements;
|
||||||
|
|
||||||
pub struct DeleteNonCodegenStatements<'tcx> {
|
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements {
|
impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements {
|
||||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
let mut delete = DeleteNonCodegenStatements { tcx };
|
for basic_block in body.basic_blocks.as_mut_preserves_cfg() {
|
||||||
delete.visit_body_preserves_cfg(body);
|
for statement in basic_block.statements.iter_mut() {
|
||||||
|
match statement.kind {
|
||||||
|
StatementKind::AscribeUserType(..)
|
||||||
|
| StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Shallow, _)))
|
||||||
|
| StatementKind::FakeRead(..) => statement.make_nop(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
body.user_type_annotations.raw.clear();
|
body.user_type_annotations.raw.clear();
|
||||||
|
|
||||||
for decl in &mut body.local_decls {
|
for decl in &mut body.local_decls {
|
||||||
|
@ -41,19 +44,3 @@ impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements<'tcx> {
|
|
||||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
|
||||||
self.tcx
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
|
|
||||||
match statement.kind {
|
|
||||||
StatementKind::AscribeUserType(..)
|
|
||||||
| StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Shallow, _)))
|
|
||||||
| StatementKind::FakeRead(..) => statement.make_nop(),
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
self.super_statement(statement, location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue