@@ -248,7 +248,7 @@ data as mutable).
248
248
2. `LIFETIME(LV, LT, MQ)`: The lifetime of the borrow does not exceed
249
249
the lifetime of the value being borrowed. This pass is also
250
250
responsible for inserting root annotations to keep managed values
251
- alive and for dynamically freezing `@mut` boxes .
251
+ alive.
252
252
253
253
3. `RESTRICTIONS(LV, LT, ACTIONS) = RS`: This pass checks and computes the
254
254
restrictions to maintain memory safety. These are the restrictions
@@ -308,22 +308,17 @@ be borrowed if MQ is immutable or const:
308
308
309
309
### Checking mutability of mutable pointer types
310
310
311
- `&mut T` and `@mut T` can be frozen, so it is acceptable to borrow
312
- them as either imm or mut:
311
+ `&mut T` can be frozen, so it is acceptable to borrow it as either imm or mut:
313
312
314
313
MUTABILITY(*LV, MQ) // M-Deref-Borrowed-Mut
315
314
TYPE(LV) = &mut Ty
316
315
317
- MUTABILITY(*LV, MQ) // M-Deref-Managed-Mut
318
- TYPE(LV) = @mut Ty
319
-
320
316
## Checking lifetime
321
317
322
- These rules aim to ensure that no data is borrowed for a scope that
323
- exceeds its lifetime. In addition, these rules manage the rooting and
324
- dynamic freezing of `@` and `@mut` values. These two computations wind
325
- up being intimately related. Formally, we define a predicate
326
- `LIFETIME(LV, LT, MQ)`, which states that "the lvalue `LV` can be
318
+ These rules aim to ensure that no data is borrowed for a scope that exceeds
319
+ its lifetime. In addition, these rules manage the rooting of `@` values.
320
+ These two computations wind up being intimately related. Formally, we define
321
+ a predicate `LIFETIME(LV, LT, MQ)`, which states that "the lvalue `LV` can be
327
322
safely borrowed for the lifetime `LT` with mutability `MQ`". The Rust
328
323
code corresponding to this predicate is the module
329
324
`middle::borrowck::gather_loans::lifetime`.
@@ -352,7 +347,7 @@ The scope of a managed referent is also the scope of the pointer. This
352
347
is a conservative approximation, since there may be other aliases fo
353
348
that same managed box that would cause it to live longer:
354
349
355
- SCOPE(*LV) = SCOPE(LV) if LV has type @T or @mut T
350
+ SCOPE(*LV) = SCOPE(LV) if LV has type @T
356
351
357
352
The scope of a borrowed referent is the scope associated with the
358
353
pointer. This is a conservative approximation, since the data that
@@ -441,29 +436,6 @@ makes a note in a side-table that the box `LV` must be rooted into the
441
436
stack when `*LV` is evaluated, and that this root can be released when
442
437
the scope `LT` exits.
443
438
444
- ### Checking lifetime for derefs of managed, mutable pointers
445
-
446
- Loans of the contents of mutable managed pointers are simpler in some
447
- ways that loans of immutable managed pointers, because we can never
448
- rely on the user to root them (since the contents are, after all,
449
- mutable). This means that the burden always falls to the compiler, so
450
- there is only one rule:
451
-
452
- LIFETIME(*LV, LT, MQ) // L-Deref-Managed-Mut-Compiler-Root
453
- TYPE(LV) = @mut Ty
454
- LT <= innermost enclosing loop/func
455
- ROOT LV at *LV for LT
456
- LOCK LV at *LV as MQ for LT
457
-
458
- Note that there is an additional clause this time `LOCK LV at *LV as
459
- MQ for LT`. This clause states that in addition to rooting `LV`, the
460
- compiler should also "lock" the box dynamically, meaning that we
461
- register that the box has been borrowed as mutable or immutable,
462
- depending on `MQ`. This lock will fail if the box has already been
463
- borrowed and either the old loan or the new loan is a mutable loan
464
- (multiple immutable loans are okay). The lock is released as we exit
465
- the scope `LT`.
466
-
467
439
## Computing the restrictions
468
440
469
441
The final rules govern the computation of *restrictions*, meaning that
@@ -835,15 +807,6 @@ prohibited from both freezes and claims. This would avoid the need to
835
807
prevent `const` borrows of the base pointer when the referent is
836
808
borrowed.
837
809
838
- ### Restrictions for loans of mutable managed referents
839
-
840
- With `@mut` referents, we don't make any static guarantees. But as a
841
- convenience, we still register a restriction against `*LV`, because
842
- that way if we *can* find a simple static error, we will:
843
-
844
- RESTRICTIONS(*LV, LT, ACTIONS) = [*LV, ACTIONS] // R-Deref-Managed-Borrowed
845
- TYPE(LV) = @mut Ty
846
-
847
810
# Moves and initialization
848
811
849
812
The borrow checker is also in charge of ensuring that:
0 commit comments