I just hit my nose on the issue, that current stable Rust's type system allows references to uninhabited types to exist.
MRE:
I have the current workaround to panic on the "unreachable" variant, but I actually hate this, since this will break my code during runtime when I implement the actual inner type of SupportedFooImplementors::B. I also don't want to take ownership of self in the trait method.
Is there a way to have my cake and eat it, i.e. check at compile time, that no such variant can exist? Sure, I can remove the B variant for now, but this is also not what I want.
Thanks. I actually tried this, but was scared off by this clippy warning:
Is this actually "safe" to do? I am not going to construct such references by unsafe code, but the fact that this is considered to be generally UB kinda scares me.
Lints in the nursery category are lints that have significant flaws, such as common false positives.
There is no risk in writing match *b {} unless you are writing unsafe code and b is either a raw pointer or a known-invalid reference (which should never be exposed to code not expecting it).
The warning's really meant for unsafe code that could construct bogus references. In safe rust you literally can't make an invalid reference to an uninhabited type, so match *b {} is fine for your purposes.