mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-01-09 09:11:50 +02:00
Update scopes-shadowing.md (#216)
Adding the definition of what shadowing is and how it is different from mutation.
This commit is contained in:
parent
71ce061cc2
commit
d1588e4f2f
@ -22,6 +22,8 @@ fn main() {
|
||||
|
||||
<details>
|
||||
|
||||
* 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.
|
||||
* A shadowing variable can have a different type.
|
||||
* 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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user