Understand Generated x86-64 Assembly Code for Rust Enum Pattern Matching

Learn how Rust enums are organized in memory and understand the generated assembly code for a match on an enum.

:link: Understand Generated x86-64 Assembly Code for Rust Enum Pattern Matching

Explore how Rust handles enums in memory, including the layout and discriminator usage. The article breaks down the assembly code generated to match an enum.

1 Like

This article has a couple of errors:

  • Enums without a specified repr are not guaranteed to be laid out any particular way. Everything the article says about the layout is contingent on the version of the compiler in use (and such subtle facts as whether any of the enum's fields have disallowed valies). This should be mentioned, because it is a common mistake to assume that the layout is predictable.
  • The standard term is “discriminant”, not “discriminator”.
3 Likes

I might argue that grammatically, "the byte at index 0" is a discriminator, while the values 0, 1, 2 or their semantic names are discriminants?

1 Like

Thanks for the feedback. I have incorporated both the changes in the document.

Looks like the term discriminant is used in both scenarios.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.