1
1
use rustc:: hir;
2
2
use rustc:: mir:: ProjectionElem ;
3
- use rustc:: mir:: { Mir , Place , NeoPlace , PlaceBase , Mutability } ;
3
+ use rustc:: mir:: { Mir , NeoPlace , PlaceBase , Mutability } ;
4
4
use rustc:: mir:: tcx:: PlaceTy ;
5
5
use rustc:: ty:: { self , TyCtxt } ;
6
6
use borrow_check:: borrow_set:: LocalsStateAtExit ;
@@ -19,64 +19,6 @@ crate trait PlaceExt<'tcx> {
19
19
) -> bool ;
20
20
}
21
21
22
- impl < ' tcx > PlaceExt < ' tcx > for Place < ' tcx > {
23
- fn ignore_borrow (
24
- & self ,
25
- tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
26
- mir : & Mir < ' tcx > ,
27
- locals_state_at_exit : & LocalsStateAtExit ,
28
- ) -> bool {
29
- let neo_place = tcx. as_new_place ( self ) ;
30
- let mut is_unsafe_place = match & neo_place. base {
31
- // If a local variable is immutable, then we only need to track borrows to guard
32
- // against two kinds of errors:
33
- // * The variable being dropped while still borrowed (e.g., because the fn returns
34
- // a reference to a local variable)
35
- // * The variable being moved while still borrowed
36
- //
37
- // In particular, the variable cannot be mutated -- the "access checks" will fail --
38
- // so we don't have to worry about mutation while borrowed.
39
- PlaceBase :: Local ( index) => {
40
- match locals_state_at_exit {
41
- LocalsStateAtExit :: AllAreInvalidated => false ,
42
- LocalsStateAtExit :: SomeAreInvalidated { has_storage_dead_or_moved } => {
43
- let ignore = !has_storage_dead_or_moved. contains ( * index) &&
44
- mir. local_decls [ * index] . mutability == Mutability :: Not ;
45
- debug ! ( "ignore_borrow: local {:?} => {:?}" , index, ignore) ;
46
- ignore
47
- }
48
- }
49
- } ,
50
- PlaceBase :: Promoted ( _) => false ,
51
- PlaceBase :: Static ( static_) => {
52
- tcx. is_static ( static_. def_id ) == Some ( hir:: Mutability :: MutMutable )
53
- }
54
- } ;
55
-
56
- let mut base_ty = neo_place. base . ty ( mir) ;
57
- for elem in neo_place. elems . iter ( ) {
58
- if let ProjectionElem :: Deref = elem {
59
- if let ty:: RawPtr ( ..) | ty:: Ref ( _, _, hir:: MutImmutable ) = base_ty. sty {
60
- // For both derefs of raw pointers and `&T`
61
- // references, the original path is `Copy` and
62
- // therefore not significant. In particular,
63
- // there is nothing the user can do to the
64
- // original path that would invalidate the
65
- // newly created reference -- and if there
66
- // were, then the user could have copied the
67
- // original path into a new variable and
68
- // borrowed *that* one, leaving the original
69
- // path unborrowed.
70
- is_unsafe_place = true ;
71
- }
72
- }
73
- base_ty = PlaceTy :: from ( base_ty) . projection_ty ( tcx, elem) . to_ty ( tcx) ;
74
- }
75
-
76
- is_unsafe_place
77
- }
78
- }
79
-
80
22
impl < ' tcx > PlaceExt < ' tcx > for NeoPlace < ' tcx > {
81
23
fn ignore_borrow (
82
24
& self ,
0 commit comments