mbcx: &'visit mut MirBorrowckCtxt<'cx, 'gcx, 'tcx>,
}
+impl<'visit, 'cx, 'gcx, 'tcx> GatherUsedMutsVisitor<'visit, 'cx, 'gcx, 'tcx> {
+ fn remove_never_initialized_mut_locals(into: &Place) {
+ // Remove any locals that we found were initialized from the
+ // `never_initialized_mut_locals` set. At the end, the only remaining locals will
+ // be those that were never initialized - we will consider those as being used as
+ // they will either have been removed by unreachable code optimizations; or linted
+ // as unused variables.
+ if let Some(local) = into.base_local() {
+ debug!(
+ "visit_statement: statement={:?} local={:?} \
+ never_initialized_mut_locals={:?}",
+ statement, local, self.never_initialized_mut_locals
+ );
+ let _ = self.never_initialized_mut_locals.remove(&local);
+ }
+ }
+}
+
impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'gcx, 'tcx> {
fn visit_terminator_kind(
&mut self,
debug!("visit_terminator_kind: kind={:?}", kind);
match &kind {
TerminatorKind::Call { destination: Some((into, _)), .. } => {
- if let Some(local) = into.base_local() {
- debug!(
- "visit_terminator_kind: kind={:?} local={:?} \
- never_initialized_mut_locals={:?}",
- kind, local, self.never_initialized_mut_locals
- );
- let _ = self.never_initialized_mut_locals.remove(&local);
- }
+ self.remove_never_initialized_mut_locals(&into);
+ },
+ TerminatorKind::DropAndReplace { location, .. } => {
+ self.remove_never_initialized_mut_locals(&location);
},
_ => {},
}
) {
match &statement.kind {
StatementKind::Assign(into, _) => {
- // Remove any locals that we found were initialized from the
- // `never_initialized_mut_locals` set. At the end, the only remaining locals will
- // be those that were never initialized - we will consider those as being used as
- // they will either have been removed by unreachable code optimizations; or linted
- // as unused variables.
- if let Some(local) = into.base_local() {
- debug!(
- "visit_statement: statement={:?} local={:?} \
- never_initialized_mut_locals={:?}",
- statement, local, self.never_initialized_mut_locals
- );
- let _ = self.never_initialized_mut_locals.remove(&local);
- }
+ self.remove_never_initialized_mut_locals(into);
},
_ => {},
}