Skip to content

Commit 1091002

Browse files
committed
rename possible_borrowed to possible_origin; pass dogfood
1 parent 251c3b6 commit 1091002

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

clippy_lints/src/redundant_clone.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
8888

8989
let mir = cx.tcx.optimized_mir(def_id.to_def_id());
9090

91-
let possible_borrowed = {
92-
let mut vis = PossibleBorrowedVisitor::new(mir);
91+
let possible_origin = {
92+
let mut vis = PossibleOriginVisitor::new(mir);
9393
vis.visit_body(mir);
9494
vis.into_map(cx)
9595
};
@@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
9999
.iterate_to_fixpoint()
100100
.into_results_cursor(mir);
101101
let mut possible_borrower = {
102-
let mut vis = PossibleBorrowerVisitor::new(cx, mir, possible_borrowed);
102+
let mut vis = PossibleBorrowerVisitor::new(cx, mir, possible_origin);
103103
vis.visit_body(mir);
104104
vis.into_map(cx, maybe_storage_live_result)
105105
};
@@ -515,20 +515,20 @@ struct PossibleBorrowerVisitor<'a, 'tcx> {
515515
possible_borrower: TransitiveRelation<mir::Local>,
516516
body: &'a mir::Body<'tcx>,
517517
cx: &'a LateContext<'tcx>,
518-
possible_borrowed: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
518+
possible_origin: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
519519
}
520520

521521
impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> {
522522
fn new(
523523
cx: &'a LateContext<'tcx>,
524524
body: &'a mir::Body<'tcx>,
525-
possible_borrowed: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
525+
possible_origin: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
526526
) -> Self {
527527
Self {
528528
possible_borrower: TransitiveRelation::default(),
529529
cx,
530530
body,
531-
possible_borrowed,
531+
possible_origin,
532532
}
533533
}
534534

@@ -620,8 +620,8 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
620620

621621
let mut mutable_variables: Vec<mir::Local> = mutable_borrowers
622622
.iter()
623-
.filter_map(|r| self.possible_borrowed.get(r))
624-
.flat_map(|r| r.iter())
623+
.filter_map(|r| self.possible_origin.get(r))
624+
.flat_map(HybridBitSet::iter)
625625
.collect();
626626

627627
if ContainsRegion.visit_ty(self.body.local_decls[*dest].ty).is_break() {
@@ -643,15 +643,15 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
643643
/// Collect possible borrowed for every `&mut` local.
644644
/// For exampel, `_1 = &mut _2` generate _1: {_2,...}
645645
/// Known Problems: not sure all borrowed are tracked
646-
struct PossibleBorrowedVisitor<'a, 'tcx> {
647-
possible_borrowed: TransitiveRelation<mir::Local>,
646+
struct PossibleOriginVisitor<'a, 'tcx> {
647+
possible_origin: TransitiveRelation<mir::Local>,
648648
body: &'a mir::Body<'tcx>,
649649
}
650650

651-
impl<'a, 'tcx> PossibleBorrowedVisitor<'a, 'tcx> {
651+
impl<'a, 'tcx> PossibleOriginVisitor<'a, 'tcx> {
652652
fn new(body: &'a mir::Body<'tcx>) -> Self {
653653
Self {
654-
possible_borrowed: TransitiveRelation::default(),
654+
possible_origin: TransitiveRelation::default(),
655655
body,
656656
}
657657
}
@@ -663,7 +663,7 @@ impl<'a, 'tcx> PossibleBorrowedVisitor<'a, 'tcx> {
663663
continue;
664664
}
665665

666-
let borrowers = self.possible_borrowed.reachable_from(&row);
666+
let borrowers = self.possible_origin.reachable_from(&row);
667667
if !borrowers.is_empty() {
668668
let mut bs = HybridBitSet::new_empty(self.body.local_decls.len());
669669
for &c in borrowers {
@@ -681,22 +681,19 @@ impl<'a, 'tcx> PossibleBorrowedVisitor<'a, 'tcx> {
681681
}
682682
}
683683

684-
impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowedVisitor<'a, 'tcx> {
684+
impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleOriginVisitor<'a, 'tcx> {
685685
fn visit_assign(&mut self, place: &mir::Place<'tcx>, rvalue: &mir::Rvalue<'_>, _location: mir::Location) {
686686
let lhs = place.local;
687687
match rvalue {
688688
// Only consider `&mut`, which can modify origin place
689-
mir::Rvalue::Ref(_, rustc_middle::mir::BorrowKind::Mut { .. }, borrowed) => {
690-
self.possible_borrowed.add(lhs, borrowed.local);
691-
},
689+
mir::Rvalue::Ref(_, rustc_middle::mir::BorrowKind::Mut { .. }, borrowed) |
692690
// _2: &mut _;
693691
// _3 = move _2
694-
mir::Rvalue::Use(mir::Operand::Move(borrowed)) => {
695-
self.possible_borrowed.add(lhs, borrowed.local);
696-
},
692+
mir::Rvalue::Use(mir::Operand::Move(borrowed)) |
697693
// _3 = move _2 as &mut _;
698-
mir::Rvalue::Cast(_, mir::Operand::Move(borrowed), _) => {
699-
self.possible_borrowed.add(lhs, borrowed.local);
694+
mir::Rvalue::Cast(_, mir::Operand::Move(borrowed), _)
695+
=> {
696+
self.possible_origin.add(lhs, borrowed.local);
700697
},
701698
_ => {},
702699
}

0 commit comments

Comments
 (0)