Why is `&Void` not an empty type when `Void` is?
⚓ Rust 📅 2026-03-11 👤 surdeus 👁️ 6I am wondering why &Void is not considered an empty type, when Void is, as, IIRC, p: &Void must point to a valid value of type Void, which there cannot be.
Making this would simplify code where you pattern match on a reference of an enum of which some branches are void.
EDIT: Apparently the question was not clear enough. An empty type in Rust has nothing to do with the void type in C. I am not speaking about ZST (zero-sized types), such as (). I am speaking of types such as Infallible and !, which are defined as follows
enum Infallible {}
Being an empty type is something that propagates in Rust, for instance, consider the following
enum Void {}
struct Empty {
foo: String,
bar: Vec<u32>,
boz: Void,
}
fn absurd<T>(e: Empty) -> T {
match e {}
}
this compiles because Rust is smart enough that no value of type Empty can be created, because that would entail that there would be a value of type Void, which there isn't.
The point of the question is: why this doesn't propagate to references too.
10 posts - 7 participants
🏷️ Rust_feed