@@ -52,6 +52,24 @@ struct GatherUsedMutsVisitor<'visit, 'cx: 'visit, 'gcx: 'tcx, 'tcx: 'cx> {
5252 mbcx : & ' visit mut MirBorrowckCtxt < ' cx , ' gcx , ' tcx > ,
5353}
5454
55+ impl < ' visit , ' cx , ' gcx , ' tcx > GatherUsedMutsVisitor < ' visit , ' cx , ' gcx , ' tcx > {
56+ fn remove_never_initialized_mut_locals ( into : & Place ) {
57+ // Remove any locals that we found were initialized from the
58+ // `never_initialized_mut_locals` set. At the end, the only remaining locals will
59+ // be those that were never initialized - we will consider those as being used as
60+ // they will either have been removed by unreachable code optimizations; or linted
61+ // as unused variables.
62+ if let Some ( local) = into. base_local ( ) {
63+ debug ! (
64+ "visit_statement: statement={:?} local={:?} \
65+ never_initialized_mut_locals={:?}",
66+ statement, local, self . never_initialized_mut_locals
67+ ) ;
68+ let _ = self . never_initialized_mut_locals . remove ( & local) ;
69+ }
70+ }
71+ }
72+
5573impl < ' visit , ' cx , ' gcx , ' tcx > Visitor < ' tcx > for GatherUsedMutsVisitor < ' visit , ' cx , ' gcx , ' tcx > {
5674 fn visit_terminator_kind (
5775 & mut self ,
@@ -61,14 +79,10 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
6179 debug ! ( "visit_terminator_kind: kind={:?}" , kind) ;
6280 match & kind {
6381 TerminatorKind :: Call { destination : Some ( ( into, _) ) , .. } => {
64- if let Some ( local) = into. base_local ( ) {
65- debug ! (
66- "visit_terminator_kind: kind={:?} local={:?} \
67- never_initialized_mut_locals={:?}",
68- kind, local, self . never_initialized_mut_locals
69- ) ;
70- let _ = self . never_initialized_mut_locals . remove ( & local) ;
71- }
82+ self . remove_never_initialized_mut_locals ( & into) ;
83+ } ,
84+ TerminatorKind :: DropAndReplace { location, .. } => {
85+ self . remove_never_initialized_mut_locals ( & location) ;
7286 } ,
7387 _ => { } ,
7488 }
@@ -81,19 +95,7 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
8195 ) {
8296 match & statement. kind {
8397 StatementKind :: Assign ( into, _) => {
84- // Remove any locals that we found were initialized from the
85- // `never_initialized_mut_locals` set. At the end, the only remaining locals will
86- // be those that were never initialized - we will consider those as being used as
87- // they will either have been removed by unreachable code optimizations; or linted
88- // as unused variables.
89- if let Some ( local) = into. base_local ( ) {
90- debug ! (
91- "visit_statement: statement={:?} local={:?} \
92- never_initialized_mut_locals={:?}",
93- statement, local, self . never_initialized_mut_locals
94- ) ;
95- let _ = self . never_initialized_mut_locals . remove ( & local) ;
96- }
98+ self . remove_never_initialized_mut_locals ( into) ;
9799 } ,
98100 _ => { } ,
99101 }
0 commit comments