[ty] Support variable-length tuples in unpacking assignments (#18948)

This PR updates our unpacking assignment logic to use the new tuple
machinery. As a result, we can now unpack variable-length tuples
correctly.

As part of this, the `TupleSpec` classes have been renamed to `Tuple`,
and can now contain any element (Rust) type, not just `Type<'db>`. The
unpacker uses a tuple of `UnionBuilder`s to maintain the types that will
be assigned to each target, as we iterate through potentially many union
elements on the rhs. We also add a new consuming iterator for tuples,
and update the `all_elements` methods to wrap the result in an enum
(similar to `itertools::Position`) letting you know which part of the
tuple each element appears in. I also added a new
`UnionBuilder::try_build`, which lets you specify a different fallback
type if the union contains no elements.
This commit is contained in:
Douglas Creager 2025-06-27 15:29:04 -04:00 committed by GitHub
parent a50a993b9c
commit c60e590b4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 779 additions and 423 deletions

View file

@ -24,7 +24,7 @@ error[invalid-assignment]: Not enough values to unpack
1 | [a, *b, c, d] = (1, 2) # error: [invalid-assignment]
| ^^^^^^^^^^^^^ ------ Got 2
| |
| Expected 3 or more
| Expected at least 3
|
info: rule `invalid-assignment` is enabled by default