Skip to content

Inconsistent pattern matching on struct variants #21033

Closed
@thchittenden

Description

@thchittenden
enum StructVar {
    BoxedInt { boxed: Box<i32> },
    UnboxedInt { unboxed: i32 }
}

fn main() {

    let x = StructVar::BoxedInt { boxed: box 3 };

    match x {
        //StructVar::BoxedInt { box boxed } => { } // expected identifier, found keyword 'box'
        StructVar::BoxedInt { boxed: box boxed } => { } // ok
        StructVar::UnboxedInt { unboxed } => { } 
    }

    match x { 
        StructVar::BoxedInt { ref boxed } => { } // works with ref
        StructVar::UnboxedInt { ref unboxed } => { }
    }

}

I'm not sure if this is actually an issue or if it's known behavior but it seems inconsistent to be able to match against ref and not box, especially since the same works with regular enums.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-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