1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-24 17:56:45 +02:00

Add speaker notes for shared and unique borrows

This commit is contained in:
Fabian Bornhofen
2023-01-10 15:51:56 +01:00
parent e29c3bfb99
commit 91b8d33a99

View File

@ -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>