1 #![deny(rustc::untranslatable_diagnostic)]
2 #![deny(rustc::diagnostic_outside_of_impl)]
4 use std
::collections
::BTreeSet
;
6 use rustc_middle
::mir
::visit
::{PlaceContext, Visitor}
;
7 use rustc_middle
::mir
::{Body, Local, Location}
;
9 /// Find all uses of (including assignments to) a [`Local`].
11 /// Uses `BTreeSet` so output is deterministic.
12 pub(super) fn find
<'tcx
>(body
: &Body
<'tcx
>, local
: Local
) -> BTreeSet
<Location
> {
13 let mut visitor
= AllLocalUsesVisitor { for_local: local, uses: BTreeSet::default() }
;
14 visitor
.visit_body(body
);
18 struct AllLocalUsesVisitor
{
20 uses
: BTreeSet
<Location
>,
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
);