Skip to content

Match destructuring in alternations should be generic over types #525

@mdinger

Description

@mdinger
#![feature(globs)]

use Char::*;

enum Char {
    A(int),
    B(i32),
    C(char),
}
fn main(){ 
    let a = Char::A(7);

    // This match doesn't work because `x` changes type inside
    // one arm. The compiler should take this and generate an
    // equivalent of the second `match` example.
    match a {
        A(x) | B(x) | C(x) => println!("{}", x),
    }

    // This works because `x` doesn't change type inside an arm.
    match a {
        A(x) => println!("{}", x),
        B(x) => println!("{}", x),
        C(x) => println!("{}", x),
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions