diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-12-17 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-12-17 18:23:37 +0100 |
| commit | 2a8513d221cfeb76c284a47e972961d22bdf65ad (patch) | |
| tree | 8249ed6efc0eb37473c0d3010176ea53b1363501 | |
| parent | aef17b7ae6160352e2814c8686f7e4b2ee04d9e4 (diff) | |
| download | rust-2a8513d221cfeb76c284a47e972961d22bdf65ad.tar.gz rust-2a8513d221cfeb76c284a47e972961d22bdf65ad.zip | |
Replace visitor with a loop over blocks and statements
| -rw-r--r-- | compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs b/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs index 3378923c22c..c33d72179ad 100644 --- a/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs +++ b/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs @@ -19,21 +19,24 @@ //! [`Nop`]: rustc_middle::mir::StatementKind::Nop use crate::MirPass; -use rustc_middle::mir::visit::MutVisitor; -use rustc_middle::mir::{Body, BorrowKind, Location, Rvalue}; -use rustc_middle::mir::{Statement, StatementKind}; +use rustc_middle::mir::{Body, BorrowKind, Rvalue, StatementKind}; use rustc_middle::ty::TyCtxt; pub struct CleanupNonCodegenStatements; -pub struct DeleteNonCodegenStatements<'tcx> { - tcx: TyCtxt<'tcx>, -} - impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let mut delete = DeleteNonCodegenStatements { tcx }; - delete.visit_body_preserves_cfg(body); + fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + for basic_block in body.basic_blocks.as_mut_preserves_cfg() { + 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(); 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); - } -} |
