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_middle::mir::StatementKind::AscribeUserType
15 //! [`Shallow`]: rustc_middle::mir::BorrowKind::Shallow
16 //! [`FakeRead`]: rustc_middle::mir::StatementKind::FakeRead
17 //! [`Nop`]: rustc_middle::mir::StatementKind::Nop
19 use crate::transform::{MirPass, MirSource};
20 use rustc_middle::mir::visit::MutVisitor;
21 use rustc_middle::mir::{BodyAndCache, BorrowKind, Location, Rvalue};
22 use rustc_middle::mir::{Statement, StatementKind};
23 use rustc_middle::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);
35 body.user_type_annotations.raw.clear();
39 impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements<'tcx> {
40 fn tcx(&self) -> TyCtxt<'tcx> {
44 fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
45 match statement.kind {
46 StatementKind::AscribeUserType(..)
47 | StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Shallow, _)))
48 | StatementKind::FakeRead(..) => statement.make_nop(),
51 self.super_statement(statement, location);