1- //! This module provides a pass to replacing the following statements with
2- //! [`Nop`]s
1+ //! This module provides a pass that removes parts of MIR that are no longer relevant after
2+ //! analysis phase and borrowck. In particular, it removes false edges, user type annotations and
3+ //! replaces following statements with [`Nop`]s:
34//!
45//! - [`AscribeUserType`]
56//! - [`FakeRead`]
67//! - [`Assign`] statements with a [`Shallow`] borrow
78//!
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.
13- //!
149//! [`AscribeUserType`]: rustc_middle::mir::StatementKind::AscribeUserType
15- //! [`Shallow`]: rustc_middle::mir::BorrowKind::Shallow
16- //! [`FakeRead`]: rustc_middle::mir::StatementKind::FakeRead
1710//! [`Assign`]: rustc_middle::mir::StatementKind::Assign
18- //! [`ForMatchGuard `]: rustc_middle::mir::FakeReadCause::ForMatchGuard
11+ //! [`FakeRead `]: rustc_middle::mir::StatementKind::FakeRead
1912//! [`Nop`]: rustc_middle::mir::StatementKind::Nop
13+ //! [`Shallow`]: rustc_middle::mir::BorrowKind::Shallow
2014
2115use crate :: MirPass ;
22- use rustc_middle:: mir:: { Body , BorrowKind , Rvalue , StatementKind } ;
16+ use rustc_middle:: mir:: { Body , BorrowKind , Rvalue , StatementKind , TerminatorKind } ;
2317use rustc_middle:: ty:: TyCtxt ;
2418
2519pub struct CleanupPostBorrowck ;
2620
2721impl < ' tcx > MirPass < ' tcx > for CleanupPostBorrowck {
2822 fn run_pass ( & self , _tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
29- for basic_block in body. basic_blocks . as_mut_preserves_cfg ( ) {
23+ for basic_block in body. basic_blocks . as_mut ( ) {
3024 for statement in basic_block. statements . iter_mut ( ) {
3125 match statement. kind {
3226 StatementKind :: AscribeUserType ( ..)
@@ -35,6 +29,14 @@ impl<'tcx> MirPass<'tcx> for CleanupPostBorrowck {
3529 _ => ( ) ,
3630 }
3731 }
32+ let terminator = basic_block. terminator_mut ( ) ;
33+ match terminator. kind {
34+ TerminatorKind :: FalseEdge { real_target, .. }
35+ | TerminatorKind :: FalseUnwind { real_target, .. } => {
36+ terminator. kind = TerminatorKind :: Goto { target : real_target } ;
37+ }
38+ _ => { }
39+ }
3840 }
3941
4042 body. user_type_annotations . raw . clear ( ) ;
0 commit comments