From 42629127a025dc9378d39b82e1aac4db2b271b01 Mon Sep 17 00:00:00 2001 From: Alexis Beingessner Date: Mon, 20 Jul 2015 11:36:26 -0700 Subject: [PATCH] mention void pointers --- exotic-sizes.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/exotic-sizes.md b/exotic-sizes.md index d4df949..68ce061 100644 --- a/exotic-sizes.md +++ b/exotic-sizes.md @@ -95,10 +95,9 @@ actually possible to communicate this at the type level by returning a knowing that it's *statically impossible* for this value to be an `Err`, as this would require providing a value of type Void. -In principle, Rust can do some interesting analysees and optimizations based +In principle, Rust can do some interesting analyses and optimizations based on this fact. For instance, `Result` could be represented as just `T`, -because the Err case doesn't actually exist. Also in principle the following -could compile: +because the Err case doesn't actually exist. The following *could* also compile: ```rust,ignore enum Void {} @@ -111,3 +110,9 @@ let Ok(num) = res; But neither of these tricks work today, so all Void types get you today is the ability to be confident that certain situations are statically impossible. + +One final subtle detail about empty types is that raw pointers to them are +actually valid to construct, but dereferencing them is Undefined Behaviour +because that doesn't actually make sense. That is, you could model C's `void *` +type with `*const Void`, but this doesn't necessarily gain anything over using +e.g. `*const ()`, which *is* safe to randomly dereference.