1
1
use rustc_index:: bit_set:: BitSet ;
2
- use rustc_middle:: mir:: visit:: Visitor ;
3
- use rustc_middle:: mir:: { self , Local , Location } ;
2
+ use rustc_middle:: mir:: { self , Local } ;
4
3
5
4
/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
6
5
///
@@ -13,12 +12,18 @@ pub struct AlwaysLiveLocals(BitSet<Local>);
13
12
14
13
impl AlwaysLiveLocals {
15
14
pub fn new ( body : & mir:: Body < ' tcx > ) -> Self {
16
- let mut ret = AlwaysLiveLocals ( BitSet :: new_filled ( body. local_decls . len ( ) ) ) ;
17
-
18
- let mut vis = StorageAnnotationVisitor ( & mut ret) ;
19
- vis. visit_body ( body) ;
15
+ let mut always_live_locals = AlwaysLiveLocals ( BitSet :: new_filled ( body. local_decls . len ( ) ) ) ;
16
+
17
+ for block in body. basic_blocks ( ) {
18
+ for statement in & block. statements {
19
+ use mir:: StatementKind :: { StorageDead , StorageLive } ;
20
+ if let StorageLive ( l) | StorageDead ( l) = statement. kind {
21
+ always_live_locals. 0 . remove ( l) ;
22
+ }
23
+ }
24
+ }
20
25
21
- ret
26
+ always_live_locals
22
27
}
23
28
24
29
pub fn into_inner ( self ) -> BitSet < Local > {
@@ -33,15 +38,3 @@ impl std::ops::Deref for AlwaysLiveLocals {
33
38
& self . 0
34
39
}
35
40
}
36
-
37
- /// Removes locals that have `Storage*` annotations from `AlwaysLiveLocals`.
38
- struct StorageAnnotationVisitor < ' a > ( & ' a mut AlwaysLiveLocals ) ;
39
-
40
- impl Visitor < ' tcx > for StorageAnnotationVisitor < ' _ > {
41
- fn visit_statement ( & mut self , statement : & mir:: Statement < ' tcx > , _location : Location ) {
42
- use mir:: StatementKind :: { StorageDead , StorageLive } ;
43
- if let StorageLive ( l) | StorageDead ( l) = statement. kind {
44
- ( self . 0 ) . 0 . remove ( l) ;
45
- }
46
- }
47
- }
0 commit comments