]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs
Auto merge of #105085 - oli-obk:stop_promoting_all_the_things, r=RalfJung
[rust.git] / compiler / rustc_borrowck / src / diagnostics / find_all_local_uses.rs
1 #![deny(rustc::untranslatable_diagnostic)]
2 #![deny(rustc::diagnostic_outside_of_impl)]
3
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.
12 pub(super) fn find(body: &Body<'_>, local: Local) -> BTreeSet<Location> {
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 {
24     fn visit_local(&mut self, local: Local, _context: PlaceContext, location: Location) {
25         if local == self.for_local {
26             self.uses.insert(location);
27         }
28     }
29 }