-
Notifications
You must be signed in to change notification settings - Fork 160
Closed
Description
I was surprised to find out that matching on bitflags leads to unreachable patterns in the example below (i.e. match_flag always return 3). I'm assuming it conflicts with the | syntax in match arms, is this the intended behavior of bitflags?
use bitflags::bitflags;
bitflags! {
pub struct Flag: u64 {
const A = 0;
const B = 1;
const C = 2;
}
}
fn match_flag(f: Flag) -> usize {
let a = Flag::A;
let ab = Flag::A | Flag::B;
let abc = Flag::A | Flag::B | Flag::C;
match f {
abc => 3,
ab => 2,
a => 1,
}
}
fn main() {
let abc = Flag::A | Flag::B | Flag::C;
let ab = Flag::A | Flag::B;
let a = Flag::A;
assert_eq!(match_flag(abc), 3);
assert_eq!(match_flag(ab), 2);
assert_eq!(match_flag(a), 2);
}
Metadata
Metadata
Assignees
Labels
No labels