@@ -52,6 +52,24 @@ struct GatherUsedMutsVisitor<'visit, 'cx: 'visit, 'gcx: 'tcx, 'tcx: 'cx> {
52
52
mbcx : & ' visit mut MirBorrowckCtxt < ' cx , ' gcx , ' tcx > ,
53
53
}
54
54
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
+
55
73
impl < ' visit , ' cx , ' gcx , ' tcx > Visitor < ' tcx > for GatherUsedMutsVisitor < ' visit , ' cx , ' gcx , ' tcx > {
56
74
fn visit_terminator_kind (
57
75
& mut self ,
@@ -61,14 +79,10 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
61
79
debug ! ( "visit_terminator_kind: kind={:?}" , kind) ;
62
80
match & kind {
63
81
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) ;
72
86
} ,
73
87
_ => { } ,
74
88
}
@@ -81,19 +95,7 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
81
95
) {
82
96
match & statement. kind {
83
97
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) ;
97
99
} ,
98
100
_ => { } ,
99
101
}
0 commit comments