3 ms·
It certainly seems incongruous to require explicit scoping on usage when identifiers are reused inline. Conceptually they have the same principle where it sh
by Lerc 10y ago
It certainly seems incongruous to require explicit scoping on usage when identifiers are reused inline. Conceptually they have the same principle where it shouldn't matter if you don't cross the streams.
- steveklabnik 10y agoThis is important for soundness; it's shadowing, not replacing let s = String::from("hello"); let s = &s[..]; Here, the second s refers to the first, and if it were go to out of scope right away, would be dangling. let s = String::from("hello"); { let s = &s[..3]; // here, s is "hell" } // here, it's the full string again This falls out of the usual scoping rules, basically. You can think of any variable introducing a new scope where it's valid; if you don't close it yourself, it's closed at the end of the enclosing scope.