1 use std::collections::BTreeSet;
3 use rustc_middle::mir::visit::{PlaceContext, Visitor};
4 use rustc_middle::mir::{Body, Local, Location};
6 /// Find all uses of (including assignments to) a [`Local`].
8 /// Uses `BTreeSet` so output is deterministic.
9 pub(super) fn find<'tcx>(body: &Body<'tcx>, local: Local) -> BTreeSet<Location> {
10 let mut visitor = AllLocalUsesVisitor { for_local: local, uses: BTreeSet::default() };
11 visitor.visit_body(body);
15 struct AllLocalUsesVisitor {
17 uses: BTreeSet<Location>,
20 impl<'tcx> Visitor<'tcx> for AllLocalUsesVisitor {
21 fn visit_local(&mut self, local: &Local, _context: PlaceContext, location: Location) {
22 if *local == self.for_local {
23 self.uses.insert(location);