@@ -25,40 +25,36 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
25
25
mir : & Mir < ' tcx > ,
26
26
locals_state_at_exit : & LocalsStateAtExit ,
27
27
) -> bool {
28
- match self {
29
- // If a local variable is immutable, then we only need to track borrows to guard
30
- // against two kinds of errors:
31
- // * The variable being dropped while still borrowed (e.g., because the fn returns
32
- // a reference to a local variable)
33
- // * The variable being moved while still borrowed
34
- //
35
- // In particular, the variable cannot be mutated -- the "access checks" will fail --
36
- // so we don't have to worry about mutation while borrowed.
37
- Place :: Base ( PlaceBase :: Local ( index) ) => {
38
- match locals_state_at_exit {
39
- LocalsStateAtExit :: AllAreInvalidated => false ,
40
- LocalsStateAtExit :: SomeAreInvalidated { has_storage_dead_or_moved } => {
41
- let ignore = !has_storage_dead_or_moved. contains ( * index) &&
42
- mir. local_decls [ * index] . mutability == Mutability :: Not ;
43
- debug ! ( "ignore_borrow: local {:?} => {:?}" , index, ignore) ;
44
- ignore
28
+ self . iterate ( |place_base, place_projection| {
29
+ let ignore = match place_base {
30
+ // If a local variable is immutable, then we only need to track borrows to guard
31
+ // against two kinds of errors:
32
+ // * The variable being dropped while still borrowed (e.g., because the fn returns
33
+ // a reference to a local variable)
34
+ // * The variable being moved while still borrowed
35
+ //
36
+ // In particular, the variable cannot be mutated -- the "access checks" will fail --
37
+ // so we don't have to worry about mutation while borrowed.
38
+ PlaceBase :: Local ( index) => {
39
+ match locals_state_at_exit {
40
+ LocalsStateAtExit :: AllAreInvalidated => false ,
41
+ LocalsStateAtExit :: SomeAreInvalidated { has_storage_dead_or_moved } => {
42
+ let ignore = !has_storage_dead_or_moved. contains ( * index) &&
43
+ mir. local_decls [ * index] . mutability == Mutability :: Not ;
44
+ debug ! ( "ignore_borrow: local {:?} => {:?}" , index, ignore) ;
45
+ ignore
46
+ }
45
47
}
46
48
}
47
- }
48
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) ) =>
49
- false ,
50
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id) , .. } ) ) => {
51
- tcx. is_mutable_static ( * def_id)
52
- }
53
- Place :: Projection ( proj) => match proj. elem {
54
- ProjectionElem :: Field ( ..)
55
- | ProjectionElem :: Downcast ( ..)
56
- | ProjectionElem :: Subslice { .. }
57
- | ProjectionElem :: ConstantIndex { .. }
58
- | ProjectionElem :: Index ( _) => proj. base . ignore_borrow (
59
- tcx, mir, locals_state_at_exit) ,
49
+ PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) =>
50
+ false ,
51
+ PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id) , .. } ) => {
52
+ tcx. is_mutable_static ( * def_id)
53
+ }
54
+ } ;
60
55
61
- ProjectionElem :: Deref => {
56
+ for proj in place_projection {
57
+ if proj. elem == ProjectionElem :: Deref {
62
58
let ty = proj. base . ty ( mir, tcx) . ty ;
63
59
match ty. sty {
64
60
// For both derefs of raw pointers and `&T`
@@ -71,11 +67,13 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
71
67
// original path into a new variable and
72
68
// borrowed *that* one, leaving the original
73
69
// path unborrowed.
74
- ty:: RawPtr ( ..) | ty:: Ref ( _, _, hir:: MutImmutable ) => true ,
75
- _ => proj . base . ignore_borrow ( tcx , mir , locals_state_at_exit ) ,
70
+ ty:: RawPtr ( ..) | ty:: Ref ( _, _, hir:: MutImmutable ) => return true ,
71
+ _ => { }
76
72
}
77
73
}
78
- } ,
79
- }
74
+ }
75
+
76
+ ignore
77
+ } )
80
78
}
81
79
}
0 commit comments