The following currently fails to compile with the highly infuriating E0579:
match 1_u8 {
0..0 => "intentionally dead arm",
_ => "not so dead",
}
The use case is as follows:
macro_rules! match_range {
($e:expr, $ty:ty, {$($tt:tt)*}) => {
match $e.get() {
0..<$ty as $crate::int::RangeNewtype>::LOW
| <$ty as $crate::int::RangeNewtype>::HIGH.. => unsafe { $crate::int::unreachable_unchecked() },
$($tt)*
}
};
}
Here, $ty
is a newtype wrapper around some integer type with a restricted range of possible values as generated by another macro that outputs an implementation of the (unsafe) RangeNewtype
trait in addition to the type and its other methods. match_range!
, then, is there to be a convenient, safe and zero-cost way to satisfy the exhaustiveness checker when matching the possible values of such a type.
The role of this problem in the greater range-restricting integer newtype story is marginal, as a properly compiler-visible and nicheopt-friendly way of doing this could just integrate with the exhaustiveness checker to remove the need for this macro entirely, but in the meantime, what could just as easily be a run-of-the-mill compiler warning is an unnecessary and obstructive hard error, as illustrated by the lack of convincing reasoning in favor of the existence of the error in the documentation of E0579.