Skip to content

Commit

Permalink
Merge pull request rust-lang#723 from ehuss/never-coerce
Browse files Browse the repository at this point in the history
Minor never type additions.
  • Loading branch information
Centril authored Nov 24, 2019
2 parents 5117ac3 + 7ebaed2 commit 9e843ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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;
```

0 comments on commit 9e843ae

Please sign in to comment.