Skip to content

Inconsistency with 1-tuples #4898

Closed
Closed
@catamorphism

Description

@catamorphism

We allow patterns on 1-tuples, at least in theory:

match z {
    (x,) => { ... }
}

The parser code for 1-tuple patterns didn't quite work as intended, and I fixed that. But then I ran into the problem that I couldn't write a test because there's no way to write a 1-tuple literal or type ((x) gets parsed as x).

Is this intentional? It seems like if we're going to allow 1-tuple patterns, we should also allow 1-tuple terms (perhaps with the same (x,) syntax?)

This came up, as you might expect, because of macros: I was trying to replace structural records with tuples in the pipes code (that seemed easier than dynamically generating new struct type names) and I ran into the parser problem, which I was able to fix but not test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of RustA-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions