Skip to content

Commit 571b0fe

Browse files
committed
Clarify stability guarantee for lifetimes in enum discriminants
1 parent b05bb29 commit 571b0fe

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/core/src/mem/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,11 @@ impl<T> fmt::Debug for Discriminant<T> {
11181118
///
11191119
/// [Reference]: ../../reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations
11201120
///
1121+
/// The value of a [`Discriminant<T>`] is independent of any *lifetimes* in `T`. As such, reading
1122+
/// or writing a `Discriminant<Foo<'a>>` as a `Discriminant<Foo<'b>>` (whether via [`transmute`] or
1123+
/// otherwise) is always sound. Note that this is **not** true for other kinds of generic
1124+
/// parameters; `Discriminant<Foo<A>>` and `Discriminant<Foo<B>>` might be incompatible.
1125+
///
11211126
/// # Examples
11221127
///
11231128
/// This can be used to compare enums that carry data, while disregarding

0 commit comments

Comments
 (0)