]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / compiler / rustc_borrowck / src / diagnostics / find_all_local_uses.rs
CommitLineData
a2a8927a
XL
1use std::collections::BTreeSet;
2
3use rustc_middle::mir::visit::{PlaceContext, Visitor};
4use 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.
9pub(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
15struct AllLocalUsesVisitor {
16 for_local: Local,
17 uses: BTreeSet<Location>,
18}
19
20impl<'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}