1 use rustc_middle::mir::visit::PlaceContext;
2 use rustc_middle::mir::visit::Visitor;
3 use rustc_middle::mir::{Body, Local, Location};
5 pub trait FindAssignments {
6 // Finds all statements that assign directly to local (i.e., X = ...)
7 // and returns their locations.
8 fn find_assignments(&self, local: Local) -> Vec<Location>;
11 impl<'tcx> FindAssignments for Body<'tcx> {
12 fn find_assignments(&self, local: Local) -> Vec<Location> {
13 let mut visitor = FindLocalAssignmentVisitor { needle: local, locations: vec![] };
14 visitor.visit_body(self);
19 // The Visitor walks the MIR to return the assignment statements corresponding
21 struct FindLocalAssignmentVisitor {
23 locations: Vec<Location>,
26 impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
27 fn visit_local(&mut self, local: Local, place_context: PlaceContext, location: Location) {
28 if self.needle != local {
32 if place_context.is_place_assignment() {
33 self.locations.push(location);