From 77d3ac01e76e51f69ce05d0ee2ca3721b93d063b Mon Sep 17 00:00:00 2001 From: Fabian Bornhofen Date: Mon, 9 Jan 2023 17:21:54 +0100 Subject: [PATCH] Add speaker notes for scopes-shadowing.md --- src/basic-syntax/scopes-shadowing.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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}"); +} +``` + +