Skip to content

Allow alternation within sub-patterns #17180

Closed

Description

@mbrubeck

Allowing | to be used within a sub-pattern would allow some match expressions on tuples and structs to be written much more clearly and concisely.

For example, the following match expression:

match (x, y) {
    (A|B, C|D) => 0,
    _ => 1
}

would be equivalent to this expanded version:

match (x, y) {
    (A, C) => 0,
    (A, D) => 0,
    (B, C) => 0,
    (B, D) => 0,
    _ => 1
}

Activity

  1. ftxqxd commented on Sep 12, 2014

    @ftxqxd
    Contributor

    rust-lang/rfcs#99 proposed such an addition (among other things), but was postponed until post-1.0.

  2. alexcrichton commented on Sep 16, 2014

    @alexcrichton
    Member

    As @P1start mentioned, this is currently a postponed RFC, so I'm closing in favor of that.

  3. mbrubeck commented on Jul 8, 2017

    @mbrubeck
    ContributorAuthor

    rust-lang/rfcs#1882 is a more recent version of this request

  4. mbrubeck commented on May 21, 2018

    @mbrubeck
    ContributorAuthor

    rust-lang/rfcs#2175 addresses part of this feature.

  5. mbrubeck commented on Sep 26, 2018

    @mbrubeck
    ContributorAuthor

    New RFC for this feature: rust-lang/rfcs#2535.

  6. mbrubeck commented on May 3, 2021

    @mbrubeck
    ContributorAuthor

    Update: RFC 2535 was implemented and will become stable in Rust 1.53.

  7. added a commit that references this issue on May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions