1
1
use std:: collections:: VecDeque ;
2
2
3
3
use rustc_data_structures:: fx:: FxIndexSet ;
4
- use rustc_middle:: mir:: visit:: { MirVisitable , PlaceContext , Visitor } ;
4
+ use rustc_middle:: mir:: visit:: { PlaceContext , Visitor } ;
5
5
use rustc_middle:: mir:: { self , Body , Local , Location } ;
6
6
use rustc_middle:: ty:: { RegionVid , TyCtxt } ;
7
7
@@ -45,7 +45,22 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
45
45
46
46
let block_data = & self . body [ p. block ] ;
47
47
48
- match self . def_use ( p, block_data. visitable ( p. statement_index ) ) {
48
+ let mut visitor = DefUseVisitor {
49
+ body : self . body ,
50
+ tcx : self . tcx ,
51
+ region_vid : self . region_vid ,
52
+ def_use_result : None ,
53
+ } ;
54
+
55
+ let is_statement = p. statement_index < block_data. statements . len ( ) ;
56
+
57
+ if is_statement {
58
+ visitor. visit_statement ( & block_data. statements [ p. statement_index ] , p) ;
59
+ } else {
60
+ visitor. visit_terminator ( block_data. terminator . as_ref ( ) . unwrap ( ) , p) ;
61
+ }
62
+
63
+ match visitor. def_use_result {
49
64
Some ( DefUseResult :: Def ) => { }
50
65
51
66
Some ( DefUseResult :: UseLive { local } ) => {
@@ -57,7 +72,7 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
57
72
}
58
73
59
74
None => {
60
- if p . statement_index < block_data . statements . len ( ) {
75
+ if is_statement {
61
76
queue. push_back ( p. successor_within_block ( ) ) ;
62
77
} else {
63
78
queue. extend (
@@ -77,19 +92,6 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
77
92
78
93
None
79
94
}
80
-
81
- fn def_use ( & self , location : Location , thing : & dyn MirVisitable < ' tcx > ) -> Option < DefUseResult > {
82
- let mut visitor = DefUseVisitor {
83
- body : self . body ,
84
- tcx : self . tcx ,
85
- region_vid : self . region_vid ,
86
- def_use_result : None ,
87
- } ;
88
-
89
- thing. apply ( location, & mut visitor) ;
90
-
91
- visitor. def_use_result
92
- }
93
95
}
94
96
95
97
struct DefUseVisitor < ' a , ' tcx > {
0 commit comments