File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,15 @@ no valid values, they cannot be instantiated.
131131enum 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
Original file line number Diff line number Diff line change 66The never type ` ! ` is a type with no values, representing the result of
77computations that never complete. Expressions of type ` ! ` can be coerced into
88any other type.
9+
10+ ``` rust,should_panic
11+ let x: ! = panic!();
12+ // Can be coerced into any type.
13+ let y: u32 = x;
14+ ```
You can’t perform that action at this time.
0 commit comments