@@ -462,10 +462,13 @@ reference, as in the following example:
462
462
``` rust
463
463
let mut b = false ;
464
464
let x = & mut b ;
465
- let c = || { * x = true ; };
466
- // The following line is an error:
467
- // let y = &x;
468
- c ();
465
+ {
466
+ let mut c = || { * x = true ; };
467
+ // The following line is an error:
468
+ // let y = &x;
469
+ c ();
470
+ }
471
+ let z = & x ;
469
472
```
470
473
471
474
In this case, borrowing ` x ` mutably is not possible, because ` x ` is not ` mut ` .
@@ -474,7 +477,8 @@ because a `& &mut` reference may not be unique, so it cannot safely be used to
474
477
modify a value. So a unique immutable borrow is used: it borrows ` x ` immutably,
475
478
but like a mutable borrow, it must be unique. In the above example, uncommenting
476
479
the declaration of ` y ` will produce an error because it would violate the
477
- uniqueness of the closure's borrow of ` x ` .
480
+ uniqueness of the closure's borrow of ` x ` ; the declaration of z is valid because
481
+ the closure's lifetime has expired at the end of the block, releasing the borrow.
478
482
479
483
### Call traits and coercions
480
484
@@ -524,12 +528,12 @@ of cloning of the captured variables is left unspecified.
524
528
Because captures are often by reference, the following general rules arise:
525
529
526
530
* A closure is [ ` Sync ` ] if all captured variables are [ ` Sync ` ] .
527
- * A closure is [ ` Send ` ] if all variables captured by shared reference are
528
- [ ` Sync ` ] , and all values captured by mutable reference, copy, or move are
529
- [ ` Send ` ] .
531
+ * A closure is [ ` Send ` ] if all variables captured by non-unique immutable
532
+ reference are [ ` Sync ` ] , and all values captured by unique immutable or mutable
533
+ reference, copy, or move are [ ` Send ` ] .
530
534
* A closure is [ ` Clone ` ] or [ ` Copy ` ] if it does not capture any values by
531
- mutable reference, and if all values it captures by copy or move are
532
- [ ` Clone ` ] or [ ` Copy ` ] , respectively.
535
+ unique immutable or mutable reference, and if all values it captures by copy
536
+ or move are [ ` Clone ` ] or [ ` Copy ` ] , respectively.
533
537
534
538
## Trait objects
535
539
0 commit comments