Skip to content

Commit 88b8cb4

Browse files
committed
---
yaml --- r: 236101 b: refs/heads/stable c: 42c2f10 h: refs/heads/master i: 236099: b44a960 v: v3
1 parent c637f7e commit 88b8cb4

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 94a89e561a62d54d25dd64329ef8af396d8ec032
32+
refs/heads/stable: 42c2f107c120e9da046c9b26aa34238fcd6549b6
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/doc/tarpl/exotic-sizes.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,33 @@ consider passing in `0` as Undefined Behaviour.
8181

8282
Rust also enables types to be declared that *cannot even be instantiated*. These
8383
types can only be talked about at the type level, and never at the value level.
84+
Empty types can be declared by specifying an enum with no variants:
8485

8586
```rust
86-
enum Foo { } // No variants = EMPTY
87+
enum Void {} // No variants = EMPTY
8788
```
8889

89-
TODO: WHY?!
90+
Empty types are even more marginal than ZSTs. The primary motivating example for
91+
Void types is type-level unreachability. For instance, suppose an API needs to
92+
return a Result in general, but a specific case actually is infallible. It's
93+
actually possible to communicate this at the type level by returning a
94+
`Result<T, Void>`. Consumers of the API can confidently unwrap such a Result
95+
knowing that it's *statically impossible* for this value to be an `Err`, as
96+
this would require providing a value of type Void.
97+
98+
In principle, Rust can do some interesting analysees and optimizations based
99+
on this fact. For instance, `Result<T, Void>` could be represented as just `T`,
100+
because the Err case doesn't actually exist. Also in principle the following
101+
could compile:
102+
103+
```rust,ignore
104+
enum Void {}
105+
106+
let res: Result<u32, Void> = Ok(0);
107+
108+
// Err doesn't exist anymore, so Ok is actually irrefutable.
109+
let Ok(num) = res;
110+
```
111+
112+
But neither of these tricks work today, so all Void types get you today is
113+
the ability to be confident that certain situations are statically impossible.

0 commit comments

Comments
 (0)