11use std:: collections:: VecDeque ;
22
33use rustc_data_structures:: fx:: FxIndexSet ;
4- use rustc_middle:: mir:: visit:: { MirVisitable , PlaceContext , Visitor } ;
4+ use rustc_middle:: mir:: visit:: { PlaceContext , Visitor } ;
55use rustc_middle:: mir:: { self , Body , Local , Location } ;
66use rustc_middle:: ty:: { RegionVid , TyCtxt } ;
77
@@ -45,7 +45,22 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
4545
4646 let block_data = & self . body [ p. block ] ;
4747
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 {
4964 Some ( DefUseResult :: Def ) => { }
5065
5166 Some ( DefUseResult :: UseLive { local } ) => {
@@ -57,7 +72,7 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
5772 }
5873
5974 None => {
60- if p . statement_index < block_data . statements . len ( ) {
75+ if is_statement {
6176 queue. push_back ( p. successor_within_block ( ) ) ;
6277 } else {
6378 queue. extend (
@@ -77,19 +92,6 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
7792
7893 None
7994 }
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- }
9395}
9496
9597struct DefUseVisitor < ' a , ' tcx > {
0 commit comments