Skip to content

Any old type of constant can be used in a pattern #20489

Closed
@nikomatsakis

Description

@nikomatsakis

Example:

struct Foo<T> {
    value: T
}

const F: Foo<int> = Foo { value: 2 };

fn main() {
    let x = Foo { value: 2 };
    match x {
        F => { println!("Hi"); }
        _ => { println!("Ho"); }
    }
}

I feel pretty sure that we would want matching to use a PartialEq impl. For now constant patterns should be limited to uint/int/&str. I'll throw it into a patch I'm working on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-mediumMedium priorityT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions