Description
The current terminology is that the (optionally explicitly specified) numerical values associated with enum
variants are called "discriminants", while the representation may use "tags".
By default (that is, unless e.g. #[repr(iN)]
/ #[repr(uN)]
is specified), discriminants have the isize
type and tags usually take the smallest signed/unsigned primitive integer that fits all the values.
All types (not just enum
s) have a "discriminant", which is always 0u8
for all non-enum
types.
For enum
s, the discriminant is computed from the memory representation, which specifically for unoptimized tagged unions is done by casting the tag to the discriminant type.
In the general case, the original discriminant values do not need to be used in-memory.
However, some of the older code in the compiler mixes up the two terms and can cause confusion.
Ideally, for enum
s, we would use "discr(iminant)" for the value associated with each variant, and "tag" for its encoding in the memory representation of tagged unions.