about summary refs log tree commit diff
path: root/src/rustllvm/PassWrapper.cpp
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2018-02-24 20:41:16 -0800
committerZack M. Davis <code@zackmdavis.net>2018-03-08 11:30:34 -0800
commit1f04597c3ca3af45236ecb496bd30db5c57daae9 (patch)
tree91d39097e6ccb473ce2dc97f92e5720ebdec9d44 /src/rustllvm/PassWrapper.cpp
parentc90f68224b069f5bb2a80e30e2737e4bb17c1466 (diff)
downloadrust-1f04597c3ca3af45236ecb496bd30db5c57daae9.tar.gz
rust-1f04597c3ca3af45236ecb496bd30db5c57daae9.zip
in which parentheses are suggested for should-have-been-tuple-patterns
Programmers used to working in some other languages (such as Python or
Go) might expect to be able to destructure values with comma-separated
identifiers but no parentheses on the left side of an assignment.

Previously, the first name in such code would get parsed as a
single-indentifier pattern—recognizing, for example, the
`let a` in `let a, b = (1, 2);`—whereupon we would have a fatal syntax
error on seeing an unexpected comma rather than the expected semicolon
(all the way nearer to the end of `parse_full_stmt`).

Instead, let's look for that comma when parsing the pattern, and if we
see it, momentarily make-believe that we're parsing the remaining
elements in a tuple pattern, so that we can suggest wrapping it all in
parentheses. We need to do this in a separate wrapper method called on
the top-level pattern (or `|`-patterns) in a `let` statement, `for`
loop, `if`- or `while let` expression, or match arm rather than within
`parse_pat` itself, because `parse_pat` gets called recursively to parse
the sub-patterns within a tuple pattern.

Resolves #48492.
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
0 files changed, 0 insertions, 0 deletions