1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-25 16:54:32 +02:00

Add speaker notes for scopes-shadowing.md

This commit is contained in:
Fabian Bornhofen 2023-01-09 17:21:54 +01:00
parent 3ff2d5f43a
commit 77d3ac01e7

View File

@ -19,3 +19,19 @@ fn main() {
println!("after: {a}");
}
```
<details>
* Shadowing looks obscure at first, but is convenient for holding on to values after `.unwrap()`.
* The following code demonstrates why the compiler can't simply reuse memory locations when shadowing an immutable variable in a scope, even if the type does not change.
```rust,editable
fn main() {
let a = 1;
let b = &a;
let a = a + 1;
println!("{a} {b}");
}
```
</details>