From 571b0fef01ea994cd9a81405283049b5595499c5 Mon Sep 17 00:00:00 2001 From: Michael Krasnitski Date: Mon, 13 Mar 2023 01:31:02 -0400 Subject: [PATCH] Clarify stability guarantee for lifetimes in enum discriminants --- library/core/src/mem/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index a67df7ed557a1..aa53aa29bdbf3 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1118,6 +1118,11 @@ impl fmt::Debug for Discriminant { /// /// [Reference]: ../../reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations /// +/// The value of a [`Discriminant`] is independent of any *lifetimes* in `T`. As such, reading +/// or writing a `Discriminant>` as a `Discriminant>` (whether via [`transmute`] or +/// otherwise) is always sound. Note that this is **not** true for other kinds of generic +/// parameters; `Discriminant>` and `Discriminant>` might be incompatible. +/// /// # Examples /// /// This can be used to compare enums that carry data, while disregarding