@@ -52,6 +52,19 @@ struct GatherUsedMutsVisitor<'visit, 'cx: 'visit, 'gcx: 'tcx, 'tcx: 'cx> {
52
52
mbcx : & ' visit mut MirBorrowckCtxt < ' cx , ' gcx , ' tcx > ,
53
53
}
54
54
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
+
55
68
impl < ' visit , ' cx , ' gcx , ' tcx > Visitor < ' tcx > for GatherUsedMutsVisitor < ' visit , ' cx , ' gcx , ' tcx > {
56
69
fn visit_terminator_kind (
57
70
& mut self ,
@@ -61,14 +74,10 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
61
74
debug ! ( "visit_terminator_kind: kind={:?}" , kind) ;
62
75
match & kind {
63
76
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) ;
72
81
} ,
73
82
_ => { } ,
74
83
}
@@ -81,19 +90,14 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
81
90
) {
82
91
match & statement. kind {
83
92
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
93
if let Some ( local) = into. base_local ( ) {
90
94
debug ! (
91
95
"visit_statement: statement={:?} local={:?} \
92
96
never_initialized_mut_locals={:?}",
93
97
statement, local, self . never_initialized_mut_locals
94
98
) ;
95
- let _ = self . never_initialized_mut_locals . remove ( & local) ;
96
99
}
100
+ self . remove_never_initialized_mut_locals ( into) ;
97
101
} ,
98
102
_ => { } ,
99
103
}
0 commit comments