Matching a reference to an uninhabited type

⚓ Rust    📅 2026-07-13    👤 surdeus    👁️ 2      

surdeus

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.

3 posts - 2 participants

Read full topic

🏷️ Rust_feed