@@ -100,7 +100,7 @@ use crate::dataflow::impls::{MaybeInitializedLocals, MaybeLiveLocals};
100
100
use crate :: dataflow:: Analysis ;
101
101
use crate :: {
102
102
transform:: MirPass ,
103
- util:: { dump_mir, PassWhere } ,
103
+ util:: { dump_mir, ever_borrowed_locals , PassWhere } ,
104
104
} ;
105
105
use itertools:: Itertools ;
106
106
use rustc_data_structures:: unify:: { InPlaceUnificationTable , UnifyKey } ;
@@ -946,68 +946,6 @@ fn is_local_required(local: Local, body: &Body<'_>) -> bool {
946
946
}
947
947
}
948
948
949
- /// Walks MIR to find all locals that have their address taken anywhere.
950
- fn ever_borrowed_locals ( body : & Body < ' _ > ) -> BitSet < Local > {
951
- let mut visitor = BorrowCollector { locals : BitSet :: new_empty ( body. local_decls . len ( ) ) } ;
952
- visitor. visit_body ( body) ;
953
- visitor. locals
954
- }
955
-
956
- struct BorrowCollector {
957
- locals : BitSet < Local > ,
958
- }
959
-
960
- impl < ' tcx > Visitor < ' tcx > for BorrowCollector {
961
- fn visit_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > , location : Location ) {
962
- self . super_rvalue ( rvalue, location) ;
963
-
964
- match rvalue {
965
- Rvalue :: AddressOf ( _, borrowed_place) | Rvalue :: Ref ( _, _, borrowed_place) => {
966
- if !borrowed_place. is_indirect ( ) {
967
- self . locals . insert ( borrowed_place. local ) ;
968
- }
969
- }
970
-
971
- Rvalue :: Cast ( ..)
972
- | Rvalue :: Use ( ..)
973
- | Rvalue :: Repeat ( ..)
974
- | Rvalue :: Len ( ..)
975
- | Rvalue :: BinaryOp ( ..)
976
- | Rvalue :: CheckedBinaryOp ( ..)
977
- | Rvalue :: NullaryOp ( ..)
978
- | Rvalue :: UnaryOp ( ..)
979
- | Rvalue :: Discriminant ( ..)
980
- | Rvalue :: Aggregate ( ..)
981
- | Rvalue :: ThreadLocalRef ( ..) => { }
982
- }
983
- }
984
-
985
- fn visit_terminator ( & mut self , terminator : & Terminator < ' tcx > , location : Location ) {
986
- self . super_terminator ( terminator, location) ;
987
-
988
- match terminator. kind {
989
- TerminatorKind :: Drop { place : dropped_place, .. }
990
- | TerminatorKind :: DropAndReplace { place : dropped_place, .. } => {
991
- self . locals . insert ( dropped_place. local ) ;
992
- }
993
-
994
- TerminatorKind :: Abort
995
- | TerminatorKind :: Assert { .. }
996
- | TerminatorKind :: Call { .. }
997
- | TerminatorKind :: FalseEdge { .. }
998
- | TerminatorKind :: FalseUnwind { .. }
999
- | TerminatorKind :: GeneratorDrop
1000
- | TerminatorKind :: Goto { .. }
1001
- | TerminatorKind :: Resume
1002
- | TerminatorKind :: Return
1003
- | TerminatorKind :: SwitchInt { .. }
1004
- | TerminatorKind :: Unreachable
1005
- | TerminatorKind :: Yield { .. }
1006
- | TerminatorKind :: InlineAsm { .. } => { }
1007
- }
1008
- }
1009
- }
1010
-
1011
949
/// `PlaceElem::Index` only stores a `Local`, so we can't replace that with a full `Place`.
1012
950
///
1013
951
/// Collect locals used as indices so we don't generate candidates that are impossible to apply
0 commit comments