Allowing opt-out would undermine the non-exhaustive feature. The only thing you can do is add a catch-all match arm or convince the crate maintainers to remove the #[non_exhaustive]
attribute.
There is a hack that will fail to link the binary when a non-exhaustive type is changed:
// Define an external function that will not exist
extern "C" {
fn _link_error();
}
fn f(kind: IntErrorKind) {
match kind {
IntErrorKind::Empty => todo!(),
IntErrorKind::InvalidDigit => todo!(),
IntErrorKind::PosOverflow => todo!(),
IntErrorKind::NegOverflow => todo!(),
IntErrorKind::Zero => todo!(),
// Fail to link when IntErrorKind adds new variants that are not covered
_ => unsafe { _link_error() },
}
}
It will compile only if all variants are covered. If any variants are not covered, you will get an obnoxious linker error. The error message will tell you which source lines are responsible, but it's always going to be hard to read. It can't be used in ![forbid(unsafe_code)]
crates. It's not ideal for several reasons.