Skip to content

Commit

Permalink
Clarify stability guarantee for lifetimes in enum discriminants
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Mar 13, 2023
1 parent b05bb29 commit 571b0fe
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,11 @@ impl<T> fmt::Debug for Discriminant<T> {
///
/// [Reference]: ../../reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations
///
/// The value of a [`Discriminant<T>`] is independent of any *lifetimes* in `T`. As such, reading
/// or writing a `Discriminant<Foo<'a>>` as a `Discriminant<Foo<'b>>` (whether via [`transmute`] or
/// otherwise) is always sound. Note that this is **not** true for other kinds of generic
/// parameters; `Discriminant<Foo<A>>` and `Discriminant<Foo<B>>` might be incompatible.
///
/// # Examples
///
/// This can be used to compare enums that carry data, while disregarding
Expand Down

0 comments on commit 571b0fe

Please sign in to comment.