Skip to content

Commit 5d9300c

Browse files
committed
Update terminology from fieldless to unit-only
1 parent 3d4745b commit 5d9300c

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

src/expressions/operator-expr.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ reference types and `mut` or `const` in pointer types.
368368
| Type of `e` | `U` | Cast performed by `e as U` |
369369
|-----------------------|-----------------------|----------------------------------|
370370
| Integer or Float type | Integer or Float type | Numeric cast |
371-
| Field-less enum | Integer type | Enum cast |
371+
| [Unit-only enum] | Integer type | Enum cast |
372372
| `bool` or `char` | Integer type | Primitive to integer cast |
373373
| `u8` | `char` | `u8` to `char` cast |
374374
| `*T` | `*V` where `V: Sized` \* | Pointer to pointer cast |
@@ -643,6 +643,7 @@ See [this test] for an example of using this dependency.
643643
[assignee expression]: ../expressions.md#place-expressions-and-value-expressions
644644
[undefined behavior]: ../behavior-considered-undefined.md
645645
[unit]: ../types/tuple.md
646+
[Unit-only enum]: ../items/enumerations.md#unit-only-enum
646647
[value expression]: ../expressions.md#place-expressions-and-value-expressions
647648
[temporary value]: ../expressions.md#temporaries
648649
[this test]: https://github.com/rust-lang/rust/blob/1.58.0/src/test/ui/expr/compound-assignment/eval-order.rs

src/items/enumerations.md

+31-18
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,26 @@ In this example, `Cat` is a _struct-like enum variant_, whereas `Dog` is simply
5959
called an enum variant.
6060

6161
An enum where no constructors contain fields are called a
62-
*<a id="field-less-enum">field-less enum</a>*.
62+
*<a id="field-less-enum">field-less enum</a>*. For example, this is a fieldless enum:
63+
64+
```rust
65+
enum Fieldless {
66+
Tuple(),
67+
Struct{},
68+
Unit,
69+
}
70+
```
71+
72+
If a field-less enum only contains unit variants, the enum is called an
73+
*<a id="unit-only-enum">unit-only enum</a>*. For example:
74+
75+
```rust
76+
enum Enum {
77+
Foo = 3,
78+
Bar = 2,
79+
Baz = 1,
80+
}
81+
```
6382

6483
## Discriminants
6584

@@ -78,15 +97,8 @@ In two circumstances, the discriminant of a variant may be explicitly set by
7897
following the variant name with `=` and a [constant expression]:
7998

8099

81-
1. if the enumeration is fieldless; e.g.:
100+
1. if the enumeration is "[unit-only]".
82101

83-
```rust
84-
enum Enum {
85-
Foo = 3,
86-
Bar() = 2,
87-
Baz {} = 1,
88-
}
89-
```
90102

91103
2. if a [primitive representation] is used. For example:
92104

@@ -161,23 +173,23 @@ enum OverflowingDiscriminantError2 {
161173

162174
[`mem::discriminant`] returns an opaque reference to the discriminant of
163175
an enum value which can be compared. This cannot be used to get the value
164-
of the discriminant.
176+
of the discriminant.
165177

166178
#### Casting
167179

168-
If an enumeration is fieldless, then its discriminant can be directly
169-
accessed with a [numeric cast]; e.g.:
180+
If an enumeration is [unit-only] (with no tuple and struct variants), then its
181+
discriminant can be directly accessed with a [numeric cast]; e.g.:
170182

171183
```rust
172184
enum Enum {
173-
Unit,
174-
Tuple(),
175-
Struct{},
185+
Foo,
186+
Bar,
187+
Baz,
176188
}
177189

178-
assert_eq!(0, Enum::Unit as isize);
179-
assert_eq!(1, Enum::Tuple() as isize);
180-
assert_eq!(2, Enum::Struct{} as isize);
190+
assert_eq!(0, Enum::Foo as isize);
191+
assert_eq!(1, Enum::Bar as isize);
192+
assert_eq!(2, Enum::Baz as isize);
181193
```
182194

183195
#### Pointer Casting
@@ -267,6 +279,7 @@ enum E {
267279
[enumerated type]: ../types/enum.md
268280
[`mem::discriminant`]: ../../std/mem/fn.discriminant.html
269281
[never type]: ../types/never.md
282+
[unit-only]: #unit-only-enum
270283
[numeric cast]: ../expressions/operator-expr.md#semantics
271284
[constant expression]: ../const_eval.md#constant-expressions
272285
[default representation]: ../type-layout.md#the-default-representation

0 commit comments

Comments
 (0)