@@ -30,54 +30,51 @@ fn place_context<'a, 'tcx, D>(
30
30
) -> ( Option < region:: Scope > , hir:: Mutability )
31
31
where D : HasLocalDecls < ' tcx >
32
32
{
33
- use rustc:: mir:: Place :: * ;
34
-
35
- match * place {
36
- Local { .. } => ( None , hir:: MutMutable ) ,
37
- Promoted ( _) |
38
- Static ( _) => ( None , hir:: MutImmutable ) ,
39
- Projection ( ref proj) => {
40
- match proj. elem {
41
- ProjectionElem :: Deref => {
42
- // Computing the inside the recursion makes this quadratic.
43
- // We don't expect deep paths though.
44
- let ty = proj. base . ty ( local_decls, tcx) . to_ty ( tcx) ;
45
- // A Deref projection may restrict the context, this depends on the type
46
- // being deref'd.
47
- let context = match ty. sty {
48
- ty:: TyRef ( re, _, mutbl) => {
49
- let re = match re {
50
- & RegionKind :: ReScope ( ce) => Some ( ce) ,
51
- & RegionKind :: ReErased =>
52
- bug ! ( "AddValidation pass must be run before erasing lifetimes" ) ,
53
- _ => None
54
- } ;
55
- ( re, mutbl)
56
- }
57
- ty:: TyRawPtr ( _) =>
58
- // There is no guarantee behind even a mutable raw pointer,
59
- // no write locks are acquired there, so we also don't want to
60
- // release any.
61
- ( None , hir:: MutImmutable ) ,
62
- ty:: TyAdt ( adt, _) if adt. is_box ( ) => ( None , hir:: MutMutable ) ,
63
- _ => bug ! ( "Deref on a non-pointer type {:?}" , ty) ,
64
- } ;
65
- // "Intersect" this restriction with proj.base.
66
- if let ( Some ( _) , hir:: MutImmutable ) = context {
67
- // This is already as restricted as it gets, no need to even recurse
68
- context
69
- } else {
70
- let base_context = place_context ( & proj. base , local_decls, tcx) ;
71
- // The region of the outermost Deref is always most restrictive.
72
- let re = context. 0 . or ( base_context. 0 ) ;
73
- let mutbl = context. 1 . and ( base_context. 1 ) ;
33
+ use rustc:: mir:: PlaceBase :: * ;
34
+ match place. elems . last ( ) {
35
+ Some ( proj) => match proj {
36
+ ProjectionElem :: Deref => {
37
+ // Computing the inside the recursion makes this quadratic.
38
+ // We don't expect deep paths though.
39
+ let ty = proj. base . ty ( local_decls, tcx) . to_ty ( tcx) ;
40
+ // A Deref projection may restrict the context, this depends on the type
41
+ // being deref'd.
42
+ let context = match ty. sty {
43
+ ty:: TyRef ( re, _, mutbl) => {
44
+ let re = match re {
45
+ & RegionKind :: ReScope ( ce) => Some ( ce) ,
46
+ & RegionKind :: ReErased =>
47
+ bug ! ( "AddValidation pass must be run before erasing lifetimes" ) ,
48
+ _ => None
49
+ } ;
74
50
( re, mutbl)
75
51
}
76
-
52
+ ty:: TyRawPtr ( _) =>
53
+ // There is no guarantee behind even a mutable raw pointer,
54
+ // no write locks are acquired there, so we also don't want to
55
+ // release any.
56
+ ( None , hir:: MutImmutable ) ,
57
+ ty:: TyAdt ( adt, _) if adt. is_box ( ) => ( None , hir:: MutMutable ) ,
58
+ _ => bug ! ( "Deref on a non-pointer type {:?}" , ty) ,
59
+ } ;
60
+ // "Intersect" this restriction with proj.base.
61
+ if let ( Some ( _) , hir:: MutImmutable ) = context {
62
+ // This is already as restricted as it gets, no need to even recurse
63
+ context
64
+ } else {
65
+ let base_context = place_context ( & place. base_place ( & tcx) , local_decls, tcx) ;
66
+ // The region of the outermost Deref is always most restrictive.
67
+ let re = context. 0 . or ( base_context. 0 ) ;
68
+ let mutbl = context. 1 . and ( base_context. 1 ) ;
69
+ ( re, mutbl)
77
70
}
78
- _ => place_context ( & proj. base , local_decls, tcx) ,
79
71
}
80
- }
72
+ _ => place_context ( & place. base_place ( & tcx) , local_decls, tcx) ,
73
+ } ,
74
+ _ => match place. base {
75
+ Local { .. } => ( None , hir:: MutMutable ) ,
76
+ Promoted ( _) | Static ( _) => ( None , hir:: MutImmutable ) ,
77
+ } ,
81
78
}
82
79
}
83
80
0 commit comments