Skip to content

rustc's ty::layout refers to tagged unions' tag as "discr(iminant)" incorrectly. #49938

Closed
@eddyb

Description

@eddyb

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 enums) have a "discriminant", which is always 0u8 for all non-enum types.
For enums, 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 enums, we would use "discr(iminant)" for the value associated with each variant, and "tag" for its encoding in the memory representation of tagged unions.

cc @oli-obk @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions