]>
Commit | Line | Data |
---|---|---|
a2a8927a XL |
1 | use std::collections::BTreeSet; |
2 | ||
3 | use rustc_middle::mir::visit::{PlaceContext, Visitor}; | |
4 | use rustc_middle::mir::{Body, Local, Location}; | |
5 | ||
6 | /// Find all uses of (including assignments to) a [`Local`]. | |
7 | /// | |
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); | |
12 | visitor.uses | |
13 | } | |
14 | ||
15 | struct AllLocalUsesVisitor { | |
16 | for_local: Local, | |
17 | uses: BTreeSet<Location>, | |
18 | } | |
19 | ||
20 | impl<'tcx> Visitor<'tcx> for AllLocalUsesVisitor { | |
064997fb FG |
21 | fn visit_local(&mut self, local: Local, _context: PlaceContext, location: Location) { |
22 | if local == self.for_local { | |
a2a8927a XL |
23 | self.uses.insert(location); |
24 | } | |
25 | } | |
26 | } |