|
19 | 19 | //! [`Nop`]: rustc_middle::mir::StatementKind::Nop
|
20 | 20 |
|
21 | 21 | 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}; |
25 | 23 | use rustc_middle::ty::TyCtxt;
|
26 | 24 |
|
27 | 25 | pub struct CleanupNonCodegenStatements;
|
28 | 26 |
|
29 |
| -pub struct DeleteNonCodegenStatements<'tcx> { |
30 |
| - tcx: TyCtxt<'tcx>, |
31 |
| -} |
32 |
| - |
33 | 27 | 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 | + |
37 | 40 | body.user_type_annotations.raw.clear();
|
38 | 41 |
|
39 | 42 | for decl in &mut body.local_decls {
|
40 | 43 | decl.user_ty = None;
|
41 | 44 | }
|
42 | 45 | }
|
43 | 46 | }
|
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