mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-17 22:16:18 +02:00
Merge pull request #145 from fbornhofen/speaker-notes-shared-unique-borrows
Add speaker notes for shared and unique borrows
This commit is contained in:
commit
a5d31d759f
@ -19,3 +19,11 @@ fn main() {
|
|||||||
println!("b: {b}");
|
println!("b: {b}");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
* The above code does not compile because `a` is borrowed as mutable (through `c`) and as immutable (through `b`) at the same time.
|
||||||
|
* Move the `println!` statement for `b` before the scope that introduces `c` to make the code compile.
|
||||||
|
* After that change, the compiler realizes that `b` is only ever used before the new mutable borrow of `a` through `c`. This is a feature of the borrow checker called "non-lexical lifetimes".
|
||||||
|
|
||||||
|
</details>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user