1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-04 03:25:08 +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:
Martin Geisler 2023-01-10 16:14:54 +01:00 committed by GitHub
commit a5d31d759f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,3 +19,11 @@ fn main() {
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>