@@ -96,46 +96,27 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
9696 self . extend ( result, cmt. mutbl , LpInterior ( i) )
9797 }
9898
99- mc:: cat_deref( cmt_base, _, pk @ mc:: OwnedPtr ) => {
100- // R-Deref-Send-Pointer
101- //
102- // When we borrow the interior of an owned pointer, we
103- // cannot permit the base to be mutated, because that
104- // would cause the unique pointer to be freed.
105- //
106- // Eventually we should make these non-special and
107- // just rely on Deref<T> implementation.
108- let result = self . restrict ( cmt_base) ;
109- self . extend ( result, cmt. mutbl , LpDeref ( pk) )
110- }
11199
112100 mc:: cat_static_item( ..) => {
113101 Safe
114102 }
115103
116- mc:: cat_deref( cmt_base, _, mc:: BorrowedPtr ( ty:: ImmBorrow , lt) ) |
117- mc:: cat_deref( cmt_base, _, mc:: Implicit ( ty:: ImmBorrow , lt) ) => {
118- // R-Deref-Imm-Borrowed
119- if !self . bccx . is_subregion_of ( self . loan_region , lt) {
120- self . bccx . report (
121- BckError {
122- span : self . span ,
123- cause : self . cause ,
124- cmt : cmt_base,
125- code : err_borrowed_pointer_too_short (
126- self . loan_region , lt) } ) ;
127- return Safe ;
128- }
129- Safe
130- }
131-
132104 mc:: cat_deref( cmt_base, _, pk) => {
133105 match pk {
134- mc:: BorrowedPtr ( ty:: MutBorrow , lt) |
135- mc:: BorrowedPtr ( ty:: UniqueImmBorrow , lt) |
136- mc:: Implicit ( ty:: MutBorrow , lt) |
137- mc:: Implicit ( ty:: UniqueImmBorrow , lt) => {
138- // R-Deref-Mut-Borrowed
106+ mc:: OwnedPtr => {
107+ // R-Deref-Send-Pointer
108+ //
109+ // When we borrow the interior of an owned pointer, we
110+ // cannot permit the base to be mutated, because that
111+ // would cause the unique pointer to be freed.
112+ //
113+ // Eventually we should make these non-special and
114+ // just rely on Deref<T> implementation.
115+ let result = self . restrict ( cmt_base) ;
116+ self . extend ( result, cmt. mutbl , LpDeref ( pk) )
117+ }
118+ mc:: Implicit ( bk, lt) | mc:: BorrowedPtr ( bk, lt) => {
119+ // R-Deref-[Mut-]Borrowed
139120 if !self . bccx . is_subregion_of ( self . loan_region , lt) {
140121 self . bccx . report (
141122 BckError {
@@ -147,25 +128,23 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
147128 return Safe ;
148129 }
149130
150- let result = self . restrict ( cmt_base ) ;
151- self . extend ( result , cmt . mutbl , LpDeref ( pk ) )
152- }
153- mc :: UnsafePtr ( .. ) => {
154- // We are very trusting when working with unsafe
155- // pointers.
156- Safe
157- }
158- _ => {
159- self . bccx . tcx . sess . span_bug ( self . span ,
160- "unhandled memcat in \
161- cat_deref" )
131+ match bk {
132+ ty :: ImmBorrow => Safe ,
133+ ty :: MutBorrow | ty :: UniqueImmBorrow => {
134+ // R-Deref-Mut-Borrowed
135+ //
136+ // The referent can be aliased after the
137+ // references lifetime ends (by a newly-unfrozen
138+ // borrow).
139+ let result = self . restrict ( cmt_base ) ;
140+ self . extend ( result , cmt . mutbl , LpDeref ( pk ) )
141+ }
142+ }
162143 }
144+ // Borrowck is not relevant for unsafe pointers
145+ mc:: UnsafePtr ( ..) => Safe
163146 }
164147 }
165-
166- mc:: cat_discr( cmt_base, _) => {
167- self . restrict ( cmt_base)
168- }
169148 }
170149 }
171150
0 commit comments