diff --git a/src/basic-syntax/scopes-shadowing.md b/src/basic-syntax/scopes-shadowing.md index c585a969..4bf76e5a 100644 --- a/src/basic-syntax/scopes-shadowing.md +++ b/src/basic-syntax/scopes-shadowing.md @@ -19,3 +19,19 @@ fn main() { println!("after: {a}"); } ``` + +
+ +* 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}"); +} +``` + +