]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / compiler / rustc_borrowck / src / diagnostics / find_all_local_uses.rs
CommitLineData
487cf647
FG
1#![deny(rustc::untranslatable_diagnostic)]
2#![deny(rustc::diagnostic_outside_of_impl)]
3
a2a8927a
XL
4use std::collections::BTreeSet;
5
6use rustc_middle::mir::visit::{PlaceContext, Visitor};
7use 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 12pub(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
18struct AllLocalUsesVisitor {
19 for_local: Local,
20 uses: BTreeSet<Location>,
21}
22
23impl<'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}