mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-04 03:25:08 +02:00
Merge pull request #136 from fbornhofen/speaker-notes-variables
Add speaker notes for scopes-shadowing.md
This commit is contained in:
commit
bee9cdab92
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user