@@ -52,6 +52,19 @@ struct GatherUsedMutsVisitor<'visit, 'cx: 'visit, 'gcx: 'tcx, 'tcx: 'cx> {
5252 mbcx : & ' visit mut MirBorrowckCtxt < ' cx , ' gcx , ' tcx > ,
5353}
5454
55+ impl GatherUsedMutsVisitor < ' _ , ' _ , ' _ , ' _ > {
56+ fn remove_never_initialized_mut_locals ( & mut self , 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+ let _ = self . never_initialized_mut_locals . remove ( & local) ;
64+ }
65+ }
66+ }
67+
5568impl < ' visit , ' cx , ' gcx , ' tcx > Visitor < ' tcx > for GatherUsedMutsVisitor < ' visit , ' cx , ' gcx , ' tcx > {
5669 fn visit_terminator_kind (
5770 & mut self ,
@@ -61,14 +74,10 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
6174 debug ! ( "visit_terminator_kind: kind={:?}" , kind) ;
6275 match & kind {
6376 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- }
77+ self . remove_never_initialized_mut_locals ( & into) ;
78+ } ,
79+ TerminatorKind :: DropAndReplace { location, .. } => {
80+ self . remove_never_initialized_mut_locals ( & location) ;
7281 } ,
7382 _ => { } ,
7483 }
@@ -81,19 +90,14 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
8190 ) {
8291 match & statement. kind {
8392 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.
8993 if let Some ( local) = into. base_local ( ) {
9094 debug ! (
9195 "visit_statement: statement={:?} local={:?} \
9296 never_initialized_mut_locals={:?}",
9397 statement, local, self . never_initialized_mut_locals
9498 ) ;
95- let _ = self . never_initialized_mut_locals . remove ( & local) ;
9699 }
100+ self . remove_never_initialized_mut_locals ( into) ;
97101 } ,
98102 _ => { } ,
99103 }
0 commit comments