Open
Description
openedon Oct 3, 2024
Repro: https://rust.godbolt.org/z/4dvWdqcn5
Today, this check
pub fn my_is_eq<T>(x: &std::cmp::Ordering) -> bool { matches!(x, std::cmp::Ordering::Equal)}
simplifies as expected down to just
bb0: {
_2 = discriminant((*_1));
_0 = Eq(copy _2, const 0_i8);
return;
}
Checking for Some
in an Option
, however,
pub fn my_is_some<T>(x: &Option<T>) -> bool { matches!(x, Some(_)) }
doesn't and ends up taking a whole five basic blocks
bb0: {
_2 = discriminant((*_1));
switchInt(move _2) -> [1: bb2, 0: bb1, otherwise: bb4];
}
bb1: {
_0 = const false;
goto -> bb3;
}
bb2: {
_0 = const true;
goto -> bb3;
}
bb3: {
return;
}
bb4: {
unreachable;
}
That's wasteful, and shouldn't happen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment