You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-24 09:46:45 +02:00
Add speaker notes for shared and unique borrows
This commit is contained in:
@ -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>
|
||||
|
Reference in New Issue
Block a user