]>
Commit | Line | Data |
---|---|---|
487cf647 FG |
1 | #![deny(rustc::untranslatable_diagnostic)] |
2 | #![deny(rustc::diagnostic_outside_of_impl)] | |
3 | ||
a2a8927a XL |
4 | use std::collections::BTreeSet; |
5 | ||
6 | use rustc_middle::mir::visit::{PlaceContext, Visitor}; | |
7 | use rustc_middle::mir::{Body, Local, Location}; | |
8 | ||
9 | /// Find all uses of (including assignments to) a [`Local`]. | |
10 | /// | |
11 | /// Uses `BTreeSet` so output is deterministic. | |
9c376795 | 12 | pub(super) fn find(body: &Body<'_>, local: Local) -> BTreeSet<Location> { |
a2a8927a XL |
13 | let mut visitor = AllLocalUsesVisitor { for_local: local, uses: BTreeSet::default() }; |
14 | visitor.visit_body(body); | |
15 | visitor.uses | |
16 | } | |
17 | ||
18 | struct AllLocalUsesVisitor { | |
19 | for_local: Local, | |
20 | uses: BTreeSet<Location>, | |
21 | } | |
22 | ||
23 | impl<'tcx> Visitor<'tcx> for AllLocalUsesVisitor { | |
064997fb FG |
24 | fn visit_local(&mut self, local: Local, _context: PlaceContext, location: Location) { |
25 | if local == self.for_local { | |
a2a8927a XL |
26 | self.uses.insert(location); |
27 | } | |
28 | } | |
29 | } |