about summary refs log tree commit diff
path: root/src/rustllvm/PassWrapper.cpp
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2018-03-08 17:25:55 -0800
committerGitHub <noreply@github.com>2018-03-08 17:25:55 -0800
commitb228b053ec719919c0c8b3410d90a7501f9b829c (patch)
tree8ba08ffdb488d2f67ac74241becca9f37c07d8b6 /src/rustllvm/PassWrapper.cpp
parent604d4ce7577b07b73d115c94fbd8007c1d9c9335 (diff)
parent1f04597c3ca3af45236ecb496bd30db5c57daae9 (diff)
downloadrust-b228b053ec719919c0c8b3410d90a7501f9b829c.tar.gz
rust-b228b053ec719919c0c8b3410d90a7501f9b829c.zip
Rollup merge of #48527 - zackmdavis:and_the_social_construction_of_tuples, r=estebank
in which parentheses are suggested for should-have-been-tuple-patterns

![destructure_suggest_parens](https://user-images.githubusercontent.com/1076988/36638335-48b082d4-19a7-11e8-9726-0d043544df2f.png)

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, 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 a "top-level"
pattern, rather than within
`parse_pat` itself, because `parse_pat` gets called recursively to parse
the sub-patterns within a tuple pattern.

~~We could also do this for `match` arms, `if let`, and `while let`, but
we elect not to in this patch, as it seems less likely for users to make
the mistake in those contexts.~~

Resolves #48492.

r? @petrochenkov
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
0 files changed, 0 insertions, 0 deletions