diff options
| author | Alexis Beingessner <a.beingessner@gmail.com> | 2015-07-20 11:36:26 -0700 |
|---|---|---|
| committer | Alexis Beingessner <a.beingessner@gmail.com> | 2015-07-20 11:36:26 -0700 |
| commit | 99043dde9dd2d0507ad2e3cda65b9d3e9244f13f (patch) | |
| tree | 960422bdf026f72ca6e87cecac62eeb994d4ca96 | |
| parent | 5f6e0abe27aa6632f95492ad8864d8084c1bacef (diff) | |
| download | rust-99043dde9dd2d0507ad2e3cda65b9d3e9244f13f.tar.gz rust-99043dde9dd2d0507ad2e3cda65b9d3e9244f13f.zip | |
mention void pointers
| -rw-r--r-- | src/doc/tarpl/exotic-sizes.md | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/doc/tarpl/exotic-sizes.md b/src/doc/tarpl/exotic-sizes.md index d4df9492da7..68ce061d8c8 100644 --- a/src/doc/tarpl/exotic-sizes.md +++ b/src/doc/tarpl/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<T, Void>` 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. |
