Skip to content

Commit 9e843ae

Browse files
authored
Merge pull request rust-lang#723 from ehuss/never-coerce
Minor never type additions.
2 parents 5117ac3 + 7ebaed2 commit 9e843ae

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/items/enumerations.md

+10
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ no valid values, they cannot be instantiated.
131131
enum ZeroVariants {}
132132
```
133133

134+
Zero-variant enums are equivalent to the [never type], but they cannot be
135+
coerced into other types.
136+
137+
```rust,compile_fail
138+
# enum ZeroVariants {}
139+
let x: ZeroVariants = panic!();
140+
let y: u32 = x; // mismatched type error
141+
```
142+
134143
[IDENTIFIER]: ../identifiers.md
135144
[_Generics_]: generics.md
136145
[_WhereClause_]: generics.md#where-clauses
@@ -139,6 +148,7 @@ enum ZeroVariants {}
139148
[_StructFields_]: structs.md
140149
[enumerated type]: ../types/enum.md
141150
[`mem::discriminant`]: ../../std/mem/fn.discriminant.html
151+
[never type]: ../types/never.md
142152
[numeric cast]: ../expressions/operator-expr.md#semantics
143153
[constant expression]: ../const_eval.md#constant-expressions
144154
[default representation]: ../type-layout.md#the-default-representation

src/types/never.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66
The never type `!` is a type with no values, representing the result of
77
computations that never complete. Expressions of type `!` can be coerced into
88
any other type.
9+
10+
```rust,should_panic
11+
let x: ! = panic!();
12+
// Can be coerced into any type.
13+
let y: u32 = x;
14+
```

0 commit comments

Comments
 (0)