Skip to content

Incomplete/confusing error when match arm is a static constant #15393

Closed
@o11c

Description

@o11c

The following code gives an error pointing to the static FOO line, but not pointing to the FOO => line, so it's not obvious that the problem is really the match. I originally encountered this from (a form of) the bitflags! macro, which was doubly confusing.

pub struct Flags
{
    bits: uint,
}

static FOO: Flags = Flags{bits: 0x01};
static BAR: Flags = Flags{bits: 0x02};

// caller is guaranteed to only set one bit here.
pub fn frob(f: Flags)
{
    match f
    {
        FOO => {}
        BAR => {}
        _ => {}
    }
}

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