diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-04-16 12:03:39 +0200 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-04-16 12:05:54 +0200 |
| commit | 2109fe4e4e3cd8b81a4f91fab8be9a30f2eee8bc (patch) | |
| tree | 8429d0a691d50b27118f2976de1f9b036bfae834 /compiler/rustc_borrowck/src/util | |
| parent | e6e956dade79bdc084dfe3078abab24656a1b483 (diff) | |
| download | rust-2109fe4e4e3cd8b81a4f91fab8be9a30f2eee8bc.tar.gz rust-2109fe4e4e3cd8b81a4f91fab8be9a30f2eee8bc.zip | |
Move some utils out of `rustc_const_eval`
This allows us to get rid of the `rustc_const_eval->rustc_borrowck` dependency edge which was delaying the compilation of borrowck. The added utils in `rustc_middle` are small and should not affect compile times there.
Diffstat (limited to 'compiler/rustc_borrowck/src/util')
| -rw-r--r-- | compiler/rustc_borrowck/src/util/collect_writes.rs | 36 | ||||
| -rw-r--r-- | compiler/rustc_borrowck/src/util/mod.rs | 3 |
2 files changed, 39 insertions, 0 deletions
diff --git a/compiler/rustc_borrowck/src/util/collect_writes.rs b/compiler/rustc_borrowck/src/util/collect_writes.rs new file mode 100644 index 00000000000..8d92bb35938 --- /dev/null +++ b/compiler/rustc_borrowck/src/util/collect_writes.rs @@ -0,0 +1,36 @@ +use rustc_middle::mir::visit::PlaceContext; +use rustc_middle::mir::visit::Visitor; +use rustc_middle::mir::{Body, Local, Location}; + +pub trait FindAssignments { + // Finds all statements that assign directly to local (i.e., X = ...) + // and returns their locations. + fn find_assignments(&self, local: Local) -> Vec<Location>; +} + +impl<'tcx> FindAssignments for Body<'tcx> { + fn find_assignments(&self, local: Local) -> Vec<Location> { + let mut visitor = FindLocalAssignmentVisitor { needle: local, locations: vec![] }; + visitor.visit_body(self); + visitor.locations + } +} + +// The Visitor walks the MIR to return the assignment statements corresponding +// to a Local. +struct FindLocalAssignmentVisitor { + needle: Local, + locations: Vec<Location>, +} + +impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor { + fn visit_local(&mut self, local: Local, place_context: PlaceContext, location: Location) { + if self.needle != local { + return; + } + + if place_context.is_place_assignment() { + self.locations.push(location); + } + } +} diff --git a/compiler/rustc_borrowck/src/util/mod.rs b/compiler/rustc_borrowck/src/util/mod.rs new file mode 100644 index 00000000000..7377d4de727 --- /dev/null +++ b/compiler/rustc_borrowck/src/util/mod.rs @@ -0,0 +1,3 @@ +mod collect_writes; + +pub use collect_writes::FindAssignments; |
