Given:
for foo, bar in [(1, 2), (3, 4)] {}
rustc produces:
error: missing `in` in `for` loop
--> src/main.rs:44:12
|
44 | for foo, bar in [(1, 2)] {}
| ^ help: try adding `in` here
error: expected expression, found `,`
--> src/main.rs:44:12
|
44 | for foo, bar in [(1, 2)] {}
| ^
…but it would be better if it figured out that the user presumably intended for (foo, bar) in ...
, and gave a more specific error message.
This is probably a somewhat common error coming from Python, which has similar syntax for for
loops but allows omitting the parentheses.
If this is something Python-inspired, then these diagnostics/recovery should ideally apply to let
as well.
let a, b = (10, 11);
=>
let (a, b) = (10, 11);
I suspect we can even implement this recovery as "auto-tupling" in all expression and pattern contexts.
illegal a, b, c
=>
(a, b, c)
:+1: Not just Python, this will be helpful for Go users as well.
for k, v := range myMap {
x, err = /* ... */
}
(I've made some progress on this; PR forthcoming)
Most helpful comment
If this is something Python-inspired, then these diagnostics/recovery should ideally apply to
let
as well.I suspect we can even implement this recovery as "auto-tupling" in all expression and pattern contexts.