Rollup merge of #78748 - fanzier:tuple-assignment, r=petrochenkov
Implement destructuring assignment for tuples This is the first step towards implementing destructuring assignment (RFC: https://github.com/rust-lang/rfcs/pull/2909, tracking issue: #71126). This PR is the first part of #71156, which was split up to allow for easier review. Quick summary: This change allows destructuring the LHS of an assignment if it's a (possibly nested) tuple. It is implemented via a desugaring (AST -> HIR lowering) as follows: ```rust (a,b) = (1,2) ``` ... becomes ... ```rust { let (lhs0,lhs1) = (1,2); a = lhs0; b = lhs1; } ``` Thanks to `@varkor` who helped with the implementation, particularly around default binding modes. r? `@petrochenkov`
This commit is contained in:
commit
abaa78baeb
23 changed files with 395 additions and 86 deletions
|
@ -732,6 +732,9 @@ pub struct Pat<'hir> {
|
|||
pub hir_id: HirId,
|
||||
pub kind: PatKind<'hir>,
|
||||
pub span: Span,
|
||||
// Whether to use default binding modes.
|
||||
// At present, this is false only for destructuring assignment.
|
||||
pub default_binding_modes: bool,
|
||||
}
|
||||
|
||||
impl Pat<'_> {
|
||||
|
@ -1680,6 +1683,9 @@ pub enum LocalSource {
|
|||
AsyncFn,
|
||||
/// A desugared `<expr>.await`.
|
||||
AwaitDesugar,
|
||||
/// A desugared `expr = expr`, where the LHS is a tuple, struct or array.
|
||||
/// The span is that of the `=` sign.
|
||||
AssignDesugar(Span),
|
||||
}
|
||||
|
||||
/// Hints at the original code for a `match _ { .. }`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue