Closed
Description
As an alternative to #20725 (which was originally about go vet), let the variables of range loops be implicitly redefined in each iteration like in Dart's for
loops. That is,
for k, v := range vals {
// ...
}
should be equivalent to
for k, v := range vals {
k := k
v := v
// ...
}
This will make it "safe" to take the loop variable's addresses as well as capturing the loop variables in nested functions (see #16520).
The proposal could be expanded to vanilla for
loops, although that would make it diverge semantically from other languages.