Skip to content

Tracking issue for const fn integration with pattern matching #57240

Closed
@Centril

Description

@Centril

Sub-tracking issue for rust-lang/rfcs#911.

This issue tracks integration of const fn with pattern matching... For example:

#[derive(PartialEq, Eq)]
struct Foo { f: usize, g: usize }

const fn ZERO(x: usize) -> Foo { Foo { f: x, g: x } }

fn main() {
    let f = Foo { f: 0, g: 1 };
    match f {
        ZERO(22) => println!("hi"),
        _ => println!("1"),
    }
}

This is currently not implemented:

error[E0532]: expected tuple struct/variant, found function `ZERO`
  --> src/main.rs:11:9
   |
11 |         ZERO(22) => println!("hi"),
   |         ^^^^ not a tuple struct/variant

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions