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 crate::transform::{MirPass, MirSource};
20 use rustc::mir::visit::MutVisitor;
21 use rustc::mir::{BodyAndCache, BorrowKind, Location, Rvalue};
22 use rustc::mir::{Statement, StatementKind};
23 use rustc::ty::TyCtxt;
25 pub struct CleanupNonCodegenStatements;
27 pub struct DeleteNonCodegenStatements<'tcx> {
31 impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements {
32 fn run_pass(&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) {
33 let mut delete = DeleteNonCodegenStatements { tcx };
34 delete.visit_body(body);
38 impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements<'tcx> {
39 fn tcx(&self) -> TyCtxt<'tcx> {
43 fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
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(statement, location);