Skip to content

Commit 26f19f7

Browse files
committed
Resolve reviews
1 parent 8a5a2f8 commit 26f19f7

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

clippy_lints/src/booleans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
343343

344344
let stats = terminal_stats(&expr);
345345
let mut simplified = expr.simplify();
346-
for simple in Bool::Not(Box::new(expr.clone())).simplify() {
346+
for simple in Bool::Not(Box::new(expr)).simplify() {
347347
match simple {
348348
Bool::Not(_) | Bool::True | Bool::False => {},
349349
_ => simplified.push(Bool::Not(Box::new(simple.clone()))),

clippy_lints/src/redundant_clone.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
137137
statement_index: bbdata.statements.len(),
138138
};
139139

140-
if from_borrow
141-
&& (cannot_move_out || possible_borrower.only_borrowers(&[arg][..], cloned, loc) != Some(true))
142-
{
140+
if from_borrow && (cannot_move_out || !possible_borrower.only_borrowers(&[arg], cloned, loc)) {
143141
continue;
144142
}
145143

@@ -171,7 +169,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
171169
block: bb,
172170
statement_index: mir.basic_blocks()[bb].statements.len(),
173171
};
174-
if cannot_move_out || possible_borrower.only_borrowers(&[arg, cloned][..], local, loc) != Some(true) {
172+
if cannot_move_out || !possible_borrower.only_borrowers(&[arg, cloned], local, loc) {
175173
continue;
176174
}
177175
local
@@ -564,29 +562,29 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
564562
struct PossibleBorrower<'a, 'tcx> {
565563
map: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
566564
maybe_live: DataflowResultsCursor<'a, 'tcx, MaybeStorageLive<'a, 'tcx>>,
565+
// Caches to avoid allocation of `BitSet` on every query
567566
bitset: (BitSet<mir::Local>, BitSet<mir::Local>),
568567
}
569568

570569
impl PossibleBorrower<'_, '_> {
571-
fn only_borrowers<'a>(
572-
&mut self,
573-
borrowers: impl IntoIterator<Item = &'a mir::Local>,
574-
borrowed: mir::Local,
575-
at: mir::Location,
576-
) -> Option<bool> {
570+
fn only_borrowers(&mut self, borrowers: &[mir::Local], borrowed: mir::Local, at: mir::Location) -> bool {
577571
self.maybe_live.seek(at);
578572

579573
self.bitset.0.clear();
580574
let maybe_live = &mut self.maybe_live;
581-
for b in self.map.get(&borrowed)?.iter().filter(move |b| maybe_live.contains(*b)) {
582-
self.bitset.0.insert(b);
575+
if let Some(bitset) = self.map.get(&borrowed) {
576+
for b in bitset.iter().filter(move |b| maybe_live.contains(*b)) {
577+
self.bitset.0.insert(b);
578+
}
579+
} else {
580+
return false;
583581
}
584582

585583
self.bitset.1.clear();
586584
for b in borrowers {
587585
self.bitset.1.insert(*b);
588586
}
589587

590-
Some(self.bitset.0 == self.bitset.1)
588+
self.bitset.0 == self.bitset.1
591589
}
592590
}

0 commit comments

Comments
 (0)