File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,7 @@ fn main() {
2323 println!("outer long: {}", long_lived_binding);
2424}
2525```
26- Also, a binding may have the same name as a binding from an outer block. This is
27- known as [ variable shadowing] [ variable-shadow ] .
26+ Also, [ variable shadowing] [ variable-shadow ] is allowed.
2827``` rust,editable,ignore,mdbook-runnable
2928fn main() {
3029 let shadowed_binding = 1;
@@ -33,11 +32,15 @@ fn main() {
3332 println!("before being shadowed: {}", shadowed_binding);
3433
3534 // This binding *shadows* the outer one
36- let shadowed_binding = "a ";
35+ let shadowed_binding = "abc ";
3736
38- println!("after being shadowed : {}", shadowed_binding);
37+ println!("shadowed in inner block : {}", shadowed_binding);
3938 }
39+ println!("outside inner block: {}", shadowed_binding);
4040
41+ // This binding *shadows* the previous binding
42+ let shadowed_binding = 2;
43+ println!("shadowed in outer block: {}", shadowed_binding);
4144}
4245```
4346[ variable-shadow ] : https://en.wikipedia.org/wiki/Variable_shadowing
You can’t perform that action at this time.
0 commit comments