Skip to content

Commit fc10179

Browse files
igor-petrukNoahDragon
authored andcommitted
Update scopes-shadowing.md (google#216)
Adding the definition of what shadowing is and how it is different from mutation.
1 parent a45adc0 commit fc10179

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/basic-syntax/scopes-shadowing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ fn main() {
2222

2323
<details>
2424

25+
* Definition: Shadowing is different from mutation, because after shadowing both variable's memory locations exist at the same time. Both are available under the same name, depending where you use it in the code.
26+
* A shadowing variable can have a different type.
2527
* Shadowing looks obscure at first, but is convenient for holding on to values after `.unwrap()`.
2628
* 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.
2729

0 commit comments

Comments
 (0)