Skip to content

Representation for assignee expressions in assignment expressions #35

Open
@xFrednet

Description

@xFrednet

The reference defines assignment expressions to have the grammar:

AssignmentExpression:
Expression = Expression

which makes sense. However, it becomes slightly more complicated when the assignee expression is an array, a tuple or a struct with fields, as these can contain wildcard/underscore and rest expressions (as shown below and on the Playground).

a += 1;
[a, b] = [1, 2];
S {
    array: [_, a, ..],
    slice: (b, ..),
} = S::default();

The wildcard/underscore expression is AFAIK only used to allow such assignments. The rest expression, is not listed and on a lexicographical level probably a range expression without limits.

While this works, it feels weird to me. When I think about assignments, I see the left-hand side as a pattern. Adding a wildcard/underscore expression just for assignments also doesn't feel quite right.

Rustc desugars such expressions into a let-statement with a pattern and variables that are then reassigned. This can be seen with Show HIR on the Playground.


The question of this issue is, how should the assignee be represented in Marker?

  1. With expressions, like the grammar would indicate
  2. With patterns and some way of including place expressions in patterns

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-stable-apiArea: Stable API, How it should look and what should be included in itC-discussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions