@@ -114,10 +114,26 @@ impl<'self> RestrictionsContext<'self> {
114
114
}
115
115
116
116
mc:: cat_copied_upvar( ..) | // FIXME(#2152) allow mutation of upvars
117
- mc:: cat_static_item( ..) |
118
- mc:: cat_deref( _, _, mc:: region_ptr( MutImmutable , _) ) |
119
- mc:: cat_deref( _, _, mc:: gc_ptr( MutImmutable ) ) => {
117
+ mc:: cat_static_item( ..) => {
118
+ Safe
119
+ }
120
+
121
+ mc:: cat_deref( cmt_base, _, mc:: region_ptr( MutImmutable , lt) ) => {
120
122
// R-Deref-Imm-Borrowed
123
+ if !self . bccx . is_subregion_of ( self . loan_region , lt) {
124
+ self . bccx . report (
125
+ BckError {
126
+ span : self . span ,
127
+ cmt : cmt_base,
128
+ code : err_borrowed_pointer_too_short (
129
+ self . loan_region , lt, restrictions) } ) ;
130
+ return Safe ;
131
+ }
132
+ Safe
133
+ }
134
+
135
+ mc:: cat_deref( _, _, mc:: gc_ptr( MutImmutable ) ) => {
136
+ // R-Deref-Imm-Managed
121
137
Safe
122
138
}
123
139
@@ -170,30 +186,19 @@ impl<'self> RestrictionsContext<'self> {
170
186
}
171
187
172
188
mc:: cat_deref( cmt_base, _, pk @ mc:: region_ptr( MutMutable , lt) ) => {
173
- // Because an `&mut` pointer does not inherit its
174
- // mutability, we can only prevent mutation or prevent
175
- // freezing if it is not aliased. Therefore, in such
176
- // cases we restrict aliasing on `cmt_base`.
177
- if restrictions != RESTR_EMPTY {
178
- if !self . bccx . is_subregion_of ( self . loan_region , lt) {
179
- self . bccx . report (
180
- BckError {
181
- span : self . span ,
182
- cmt : cmt_base,
183
- code : err_mut_pointer_too_short (
184
- self . loan_region , lt, restrictions) } ) ;
185
- return Safe ;
186
- }
187
-
188
- // R-Deref-Mut-Borrowed-1
189
- let result = self . restrict (
190
- cmt_base,
191
- RESTR_ALIAS | RESTR_MUTATE | RESTR_CLAIM ) ;
192
- self . extend ( result, cmt. mutbl , LpDeref ( pk) , restrictions)
193
- } else {
194
- // R-Deref-Mut-Borrowed-2
195
- Safe
189
+ // R-Deref-Mut-Borrowed
190
+ if !self . bccx . is_subregion_of ( self . loan_region , lt) {
191
+ self . bccx . report (
192
+ BckError {
193
+ span : self . span ,
194
+ cmt : cmt_base,
195
+ code : err_borrowed_pointer_too_short (
196
+ self . loan_region , lt, restrictions) } ) ;
197
+ return Safe ;
196
198
}
199
+
200
+ let result = self . restrict ( cmt_base, restrictions) ;
201
+ self . extend ( result, cmt. mutbl , LpDeref ( pk) , restrictions)
197
202
}
198
203
199
204
mc:: cat_deref( _, _, mc:: unsafe_ptr( ..) ) => {
0 commit comments