The spec doesn't lay out the precise rules for variable scoping. I didn't find any surprises but I still had to discover them by experimentation. This is what I gathered:
- lexical block scoping for functions, methods, if/case/for/while etc
- a new variable defined in a if/case/for/while does not outlive the block even if it has the same name and type in all branches
- you can't use let to re-define an existing variable, even if it was made in an outer scope (no shadowing)
- if a linear variable is borrowed in a
borrow block, it vanishes for the duration of the borrow block then reappears afterwards
Is this a fair description?
oh also the let-destructure section doesn't talk about the optional as fragment.
The spec doesn't lay out the precise rules for variable scoping. I didn't find any surprises but I still had to discover them by experimentation. This is what I gathered:
borrowblock, it vanishes for the duration of the borrow block then reappears afterwardsIs this a fair description?
oh also the let-destructure section doesn't talk about the optional
asfragment.