Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Dec 20, 2022
1 parent 26df551 commit c7dc961
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions clippy_utils/src/mir/possible_borrower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_mir_dataflow::{
fmt::DebugWithContext, impls::MaybeStorageLive, lattice::JoinSemiLattice, Analysis, AnalysisDomain,
CallReturnPlaces, ResultsCursor,
};
use std::collections::VecDeque;
use std::ops::ControlFlow;

/// Collects the possible borrowers of each local.
Expand Down Expand Up @@ -216,6 +215,8 @@ pub struct PossibleBorrowerMap<'b, 'tcx> {
body: &'b mir::Body<'tcx>,
possible_borrower: ResultsCursor<'b, 'tcx, PossibleBorrowerAnalysis<'b, 'tcx>>,
maybe_live: ResultsCursor<'b, 'tcx, MaybeStorageLive>,
pushed: BitSet<Local>,
stack: Vec<Local>,
}

impl<'b, 'tcx> PossibleBorrowerMap<'b, 'tcx> {
Expand All @@ -239,6 +240,8 @@ impl<'b, 'tcx> PossibleBorrowerMap<'b, 'tcx> {
body: mir,
possible_borrower,
maybe_live,
pushed: BitSet::new_empty(mir.local_decls.len()),
stack: Vec::with_capacity(mir.local_decls.len()),
}
}

Expand Down Expand Up @@ -269,29 +272,29 @@ impl<'b, 'tcx> PossibleBorrowerMap<'b, 'tcx> {
let possible_borrower = &self.possible_borrower.get().map;
let maybe_live = &self.maybe_live;

let mut queued = BitSet::new_empty(self.body.local_decls.len());
let mut deque = VecDeque::with_capacity(self.body.local_decls.len());
self.pushed.clear();
self.stack.clear();

if let Some(borrowers) = possible_borrower.get(&borrowed) {
for b in borrowers.iter() {
if queued.insert(b) {
deque.push_back(b);
if self.pushed.insert(b) {
self.stack.push(b);
}
}
} else {
// Nothing borrows `borrowed` at `at`.
return true;
}

while let Some(borrower) = deque.pop_front() {
while let Some(borrower) = self.stack.pop() {
if maybe_live.contains(borrower) && !borrowers.contains(&borrower) {
return false;
}

if let Some(borrowers) = possible_borrower.get(&borrower) {
for b in borrowers.iter() {
if queued.insert(b) {
deque.push_back(b);
if self.pushed.insert(b) {
self.stack.push(b);
}
}
}
Expand Down

0 comments on commit c7dc961

Please sign in to comment.