]>
Commit | Line | Data |
---|---|---|
9fa01778 XL |
1 | //! This module provides a pass to replacing the following statements with |
2 | //! [`Nop`]s | |
041b39d2 | 3 | //! |
9fa01778 XL |
4 | //! - [`AscribeUserType`] |
5 | //! - [`FakeRead`] | |
6 | //! - [`Assign`] statements with a [`Shallow`] borrow | |
0531ce1d | 7 | //! |
0731742a | 8 | //! The `CleanFakeReadsAndBorrows` "pass" is actually implemented as two |
0531ce1d | 9 | //! traversals (aka visits) of the input MIR. The first traversal, |
0731742a XL |
10 | //! [`DeleteAndRecordFakeReads`], deletes the fake reads and finds the |
11 | //! temporaries read by [`ForMatchGuard`] reads, and [`DeleteFakeBorrows`] | |
12 | //! deletes the initialization of those temporaries. | |
13 | //! | |
0731742a | 14 | //! [`AscribeUserType`]: rustc::mir::StatementKind::AscribeUserType |
9fa01778 | 15 | //! [`Shallow`]: rustc::mir::BorrowKind::Shallow |
0731742a | 16 | //! [`FakeRead`]: rustc::mir::StatementKind::FakeRead |
9fa01778 | 17 | //! [`Nop`]: rustc::mir::StatementKind::Nop |
041b39d2 | 18 | |
9fa01778 | 19 | use rustc::mir::{BasicBlock, BorrowKind, Rvalue, Location, Mir}; |
a1dfa0c6 XL |
20 | use rustc::mir::{Statement, StatementKind}; |
21 | use rustc::mir::visit::MutVisitor; | |
22 | use rustc::ty::TyCtxt; | |
9fa01778 | 23 | use crate::transform::{MirPass, MirSource}; |
041b39d2 | 24 | |
9fa01778 | 25 | pub struct CleanupNonCodegenStatements; |
0531ce1d | 26 | |
9fa01778 | 27 | pub struct DeleteNonCodegenStatements; |
0531ce1d | 28 | |
9fa01778 | 29 | impl MirPass for CleanupNonCodegenStatements { |
0531ce1d XL |
30 | fn run_pass<'a, 'tcx>(&self, |
31 | _tcx: TyCtxt<'a, 'tcx, 'tcx>, | |
9fa01778 | 32 | _source: MirSource<'tcx>, |
0531ce1d | 33 | mir: &mut Mir<'tcx>) { |
9fa01778 | 34 | let mut delete = DeleteNonCodegenStatements; |
0531ce1d XL |
35 | delete.visit_mir(mir); |
36 | } | |
37 | } | |
38 | ||
9fa01778 | 39 | impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements { |
0bf4aa26 XL |
40 | fn visit_statement(&mut self, |
41 | block: BasicBlock, | |
42 | statement: &mut Statement<'tcx>, | |
43 | location: Location) { | |
9fa01778 XL |
44 | match statement.kind { |
45 | StatementKind::AscribeUserType(..) | |
46 | | StatementKind::Assign(_, box Rvalue::Ref(_, BorrowKind::Shallow, _)) | |
47 | | StatementKind::FakeRead(..) => statement.make_nop(), | |
48 | _ => (), | |
0bf4aa26 XL |
49 | } |
50 | self.super_statement(block, statement, location); | |
51 | } | |
52 | } |