Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/items/enumerations.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ no valid values, they cannot be instantiated.
enum ZeroVariants {}
```

Zero-variant enums are equivalent to the [never type], but they cannot be
coerced into other types.

```rust,compile_fail
# enum ZeroVariants {}
let x: ZeroVariants = panic!();
let y: u32 = x; // mismatched type error
```

[IDENTIFIER]: ../identifiers.md
[_Generics_]: generics.md
[_WhereClause_]: generics.md#where-clauses
Expand All @@ -139,6 +148,7 @@ enum ZeroVariants {}
[_StructFields_]: structs.md
[enumerated type]: ../types/enum.md
[`mem::discriminant`]: ../../std/mem/fn.discriminant.html
[never type]: ../types/never.md
[numeric cast]: ../expressions/operator-expr.md#semantics
[constant expression]: ../const_eval.md#constant-expressions
[default representation]: ../type-layout.md#the-default-representation
Expand Down
6 changes: 6 additions & 0 deletions src/types/never.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@
The never type `!` is a type with no values, representing the result of
computations that never complete. Expressions of type `!` can be coerced into
any other type.

```rust,should_panic
let x: ! = panic!();
// Can be coerced into any type.
let y: u32 = x;
```