|
8 | 8 |
|
9 | 9 | use crate::cell::UnsafeCell; |
10 | 10 | use crate::cmp; |
| 11 | +use crate::fmt::Debug; |
11 | 12 | use crate::hash::Hash; |
12 | 13 | use crate::hash::Hasher; |
13 | 14 |
|
@@ -679,6 +680,37 @@ mod impls { |
679 | 680 | unsafe impl<T: Send + ?Sized> Send for &mut T {} |
680 | 681 | } |
681 | 682 |
|
| 683 | +/// Compiler-internal trait used to indicate the type of enum discriminants. |
| 684 | +/// |
| 685 | +/// This trait is automatically implemented for every type and does not add any |
| 686 | +/// guarantees to [`mem::Discriminant`]. It is **undefined behavior** to transmute |
| 687 | +/// between `DiscriminantKind::Discriminant` and `mem::Discriminant`. |
| 688 | +/// |
| 689 | +/// [`mem::Discriminant`]: https://doc.rust-lang.org/stable/core/mem/struct.Discriminant.html |
| 690 | +#[unstable( |
| 691 | + feature = "discriminant_kind", |
| 692 | + issue = "none", |
| 693 | + reason = "this trait is unlikely to ever be stabilized, use `mem::discriminant` instead" |
| 694 | +)] |
| 695 | +#[cfg_attr(not(bootstrap), lang = "discriminant_kind")] |
| 696 | +pub trait DiscriminantKind { |
| 697 | + /// The type of the dicriminant, which must satisfy the trait |
| 698 | + /// bounds required by `mem::Discriminant`. |
| 699 | + type Discriminant: Clone + Copy + Debug + Eq + PartialEq + Hash + Send + Sync + Unpin; |
| 700 | +} |
| 701 | + |
| 702 | +// Manually implement `DiscriminantKind` for all types during bootstrap |
| 703 | +// to reduce the required amount of conditional compilation. |
| 704 | +#[unstable( |
| 705 | + feature = "discriminant_kind", |
| 706 | + issue = "none", |
| 707 | + reason = "this trait is unlikely to ever be stabilized, use `mem::discriminant` instead" |
| 708 | +)] |
| 709 | +#[cfg(bootstrap)] |
| 710 | +impl<T: ?Sized> DiscriminantKind for T { |
| 711 | + type Discriminant = u64; |
| 712 | +} |
| 713 | + |
682 | 714 | /// Compiler-internal trait used to determine whether a type contains |
683 | 715 | /// any `UnsafeCell` internally, but not through an indirection. |
684 | 716 | /// This affects, for example, whether a `static` of that type is |
|
0 commit comments