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