8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- //! This module provides one pass, `CleanEndRegions`, that reduces the
12
- //! set of `EndRegion` statements in the MIR.
11
+ //! This module provides two passes:
13
12
//!
14
- //! The "pass" is actually implemented as two traversals (aka visits)
15
- //! of the input MIR. The first traversal, `GatherBorrowedRegions`,
16
- //! finds all of the regions in the MIR that are involved in a borrow.
13
+ //! - `CleanEndRegions`, that reduces the set of `EndRegion` statements
14
+ //! in the MIR.
15
+ //! - `CleanUserAssertTy`, that replaces all `UserAssertTy` statements
16
+ //! with `Nop`.
17
+ //!
18
+ //! The `CleanEndRegions` "pass" is actually implemented as two
19
+ //! traversals (aka visits) of the input MIR. The first traversal,
20
+ //! `GatherBorrowedRegions`, finds all of the regions in the MIR
21
+ //! that are involved in a borrow.
17
22
//!
18
23
//! The second traversal, `DeleteTrivialEndRegions`, walks over the
19
24
//! MIR and removes any `EndRegion` that is applied to a region that
20
25
//! was not seen in the previous pass.
26
+ //!
27
+ //! The `CleanUserAssertTy` pass runs at a distinct time from the
28
+ //! `CleanEndRegions` pass. It is important that the `CleanUserAssertTy`
29
+ //! pass runs after the MIR borrowck so that the NLL type checker can
30
+ //! perform the type assertion when it encounters the `UserAssertTy`
31
+ //! statements.
21
32
22
33
use rustc_data_structures:: fx:: FxHashSet ;
23
34
@@ -27,7 +38,7 @@ use rustc::mir::visit::{MutVisitor, Visitor, TyContext};
27
38
use rustc:: ty:: { Ty , RegionKind , TyCtxt } ;
28
39
use transform:: { MirPass , MirSource } ;
29
40
30
- pub struct CleanEndRegions ;
41
+ pub struct CleanupPostBorrowck ;
31
42
32
43
struct GatherBorrowedRegions {
33
44
seen_regions : FxHashSet < region:: Scope > ,
@@ -37,19 +48,24 @@ struct DeleteTrivialEndRegions<'a> {
37
48
seen_regions : & ' a FxHashSet < region:: Scope > ,
38
49
}
39
50
40
- impl MirPass for CleanEndRegions {
51
+ pub struct DeleteUserAssertTy ;
52
+
53
+ impl MirPass for CleanupPostBorrowck {
41
54
fn run_pass < ' a , ' tcx > ( & self ,
42
55
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
43
56
_source : MirSource ,
44
57
mir : & mut Mir < ' tcx > ) {
45
- if !tcx. emit_end_regions ( ) { return ; }
58
+ if tcx. emit_end_regions ( ) {
59
+ let mut gather = GatherBorrowedRegions {
60
+ seen_regions : FxHashSet ( )
61
+ } ;
62
+ gather. visit_mir ( mir) ;
46
63
47
- let mut gather = GatherBorrowedRegions {
48
- seen_regions : FxHashSet ( )
49
- } ;
50
- gather. visit_mir ( mir) ;
64
+ let mut delete = DeleteTrivialEndRegions { seen_regions : & mut gather. seen_regions } ;
65
+ delete. visit_mir ( mir) ;
66
+ }
51
67
52
- let mut delete = DeleteTrivialEndRegions { seen_regions : & mut gather . seen_regions } ;
68
+ let mut delete = DeleteUserAssertTy ;
53
69
delete. visit_mir ( mir) ;
54
70
}
55
71
}
@@ -93,7 +109,19 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DeleteTrivialEndRegions<'a> {
93
109
}
94
110
95
111
if delete_it {
96
- statement. kind = StatementKind :: Nop ;
112
+ statement. make_nop ( ) ;
113
+ }
114
+ self . super_statement ( block, statement, location) ;
115
+ }
116
+ }
117
+
118
+ impl < ' tcx > MutVisitor < ' tcx > for DeleteUserAssertTy {
119
+ fn visit_statement ( & mut self ,
120
+ block : BasicBlock ,
121
+ statement : & mut Statement < ' tcx > ,
122
+ location : Location ) {
123
+ if let StatementKind :: UserAssertTy ( ..) = statement. kind {
124
+ statement. make_nop ( ) ;
97
125
}
98
126
self . super_statement ( block, statement, location) ;
99
127
}
0 commit comments