@@ -88,8 +88,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
88
88
89
89
let mir = cx. tcx . optimized_mir ( def_id. to_def_id ( ) ) ;
90
90
91
- let possible_borrowed = {
92
- let mut vis = PossibleBorrowedVisitor :: new ( mir) ;
91
+ let possible_origin = {
92
+ let mut vis = PossibleOriginVisitor :: new ( mir) ;
93
93
vis. visit_body ( mir) ;
94
94
vis. into_map ( cx)
95
95
} ;
@@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
99
99
. iterate_to_fixpoint ( )
100
100
. into_results_cursor ( mir) ;
101
101
let mut possible_borrower = {
102
- let mut vis = PossibleBorrowerVisitor :: new ( cx, mir, possible_borrowed ) ;
102
+ let mut vis = PossibleBorrowerVisitor :: new ( cx, mir, possible_origin ) ;
103
103
vis. visit_body ( mir) ;
104
104
vis. into_map ( cx, maybe_storage_live_result)
105
105
} ;
@@ -515,20 +515,20 @@ struct PossibleBorrowerVisitor<'a, 'tcx> {
515
515
possible_borrower : TransitiveRelation < mir:: Local > ,
516
516
body : & ' a mir:: Body < ' tcx > ,
517
517
cx : & ' a LateContext < ' tcx > ,
518
- possible_borrowed : FxHashMap < mir:: Local , HybridBitSet < mir:: Local > > ,
518
+ possible_origin : FxHashMap < mir:: Local , HybridBitSet < mir:: Local > > ,
519
519
}
520
520
521
521
impl < ' a , ' tcx > PossibleBorrowerVisitor < ' a , ' tcx > {
522
522
fn new (
523
523
cx : & ' a LateContext < ' tcx > ,
524
524
body : & ' a mir:: Body < ' tcx > ,
525
- possible_borrowed : FxHashMap < mir:: Local , HybridBitSet < mir:: Local > > ,
525
+ possible_origin : FxHashMap < mir:: Local , HybridBitSet < mir:: Local > > ,
526
526
) -> Self {
527
527
Self {
528
528
possible_borrower : TransitiveRelation :: default ( ) ,
529
529
cx,
530
530
body,
531
- possible_borrowed ,
531
+ possible_origin ,
532
532
}
533
533
}
534
534
@@ -620,8 +620,8 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
620
620
621
621
let mut mutable_variables: Vec < mir:: Local > = mutable_borrowers
622
622
. 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)
625
625
. collect ( ) ;
626
626
627
627
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> {
643
643
/// Collect possible borrowed for every `&mut` local.
644
644
/// For exampel, `_1 = &mut _2` generate _1: {_2,...}
645
645
/// 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 > ,
648
648
body : & ' a mir:: Body < ' tcx > ,
649
649
}
650
650
651
- impl < ' a , ' tcx > PossibleBorrowedVisitor < ' a , ' tcx > {
651
+ impl < ' a , ' tcx > PossibleOriginVisitor < ' a , ' tcx > {
652
652
fn new ( body : & ' a mir:: Body < ' tcx > ) -> Self {
653
653
Self {
654
- possible_borrowed : TransitiveRelation :: default ( ) ,
654
+ possible_origin : TransitiveRelation :: default ( ) ,
655
655
body,
656
656
}
657
657
}
@@ -663,7 +663,7 @@ impl<'a, 'tcx> PossibleBorrowedVisitor<'a, 'tcx> {
663
663
continue ;
664
664
}
665
665
666
- let borrowers = self . possible_borrowed . reachable_from ( & row) ;
666
+ let borrowers = self . possible_origin . reachable_from ( & row) ;
667
667
if !borrowers. is_empty ( ) {
668
668
let mut bs = HybridBitSet :: new_empty ( self . body . local_decls . len ( ) ) ;
669
669
for & c in borrowers {
@@ -681,22 +681,19 @@ impl<'a, 'tcx> PossibleBorrowedVisitor<'a, 'tcx> {
681
681
}
682
682
}
683
683
684
- impl < ' a , ' tcx > mir:: visit:: Visitor < ' tcx > for PossibleBorrowedVisitor < ' a , ' tcx > {
684
+ impl < ' a , ' tcx > mir:: visit:: Visitor < ' tcx > for PossibleOriginVisitor < ' a , ' tcx > {
685
685
fn visit_assign ( & mut self , place : & mir:: Place < ' tcx > , rvalue : & mir:: Rvalue < ' _ > , _location : mir:: Location ) {
686
686
let lhs = place. local ;
687
687
match rvalue {
688
688
// 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) |
692
690
// _2: &mut _;
693
691
// _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) ) |
697
693
// _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 ) ;
700
697
} ,
701
698
_ => { } ,
702
699
}
0 commit comments