mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-12 07:43:31 +00:00
Auto merge of #44263 - durka:stabilize-discriminant, r=dtolnay
stabilize mem::discriminant (closes #24263)
This commit is contained in:
commit
0006d3e01c
@ -711,39 +711,39 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
||||
/// Opaque type representing the discriminant of an enum.
|
||||
///
|
||||
/// See the `discriminant` function in this module for more information.
|
||||
#[unstable(feature = "discriminant_value", reason = "recently added, follows RFC", issue = "24263")]
|
||||
#[stable(feature = "discriminant_value", since = "1.22.0")]
|
||||
pub struct Discriminant<T>(u64, PhantomData<*const T>);
|
||||
|
||||
// N.B. These trait implementations cannot be derived because we don't want any bounds on T.
|
||||
|
||||
#[unstable(feature = "discriminant_value", reason = "recently added, follows RFC", issue = "24263")]
|
||||
#[stable(feature = "discriminant_value", since = "1.22.0")]
|
||||
impl<T> Copy for Discriminant<T> {}
|
||||
|
||||
#[unstable(feature = "discriminant_value", reason = "recently added, follows RFC", issue = "24263")]
|
||||
#[stable(feature = "discriminant_value", since = "1.22.0")]
|
||||
impl<T> clone::Clone for Discriminant<T> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "discriminant_value", reason = "recently added, follows RFC", issue = "24263")]
|
||||
#[stable(feature = "discriminant_value", since = "1.22.0")]
|
||||
impl<T> cmp::PartialEq for Discriminant<T> {
|
||||
fn eq(&self, rhs: &Self) -> bool {
|
||||
self.0 == rhs.0
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "discriminant_value", reason = "recently added, follows RFC", issue = "24263")]
|
||||
#[stable(feature = "discriminant_value", since = "1.22.0")]
|
||||
impl<T> cmp::Eq for Discriminant<T> {}
|
||||
|
||||
#[unstable(feature = "discriminant_value", reason = "recently added, follows RFC", issue = "24263")]
|
||||
#[stable(feature = "discriminant_value", since = "1.22.0")]
|
||||
impl<T> hash::Hash for Discriminant<T> {
|
||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||
self.0.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "discriminant_value", reason = "recently added, follows RFC", issue = "24263")]
|
||||
#[stable(feature = "discriminant_value", since = "1.22.0")]
|
||||
impl<T> fmt::Debug for Discriminant<T> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_tuple("Discriminant")
|
||||
@ -768,7 +768,6 @@ impl<T> fmt::Debug for Discriminant<T> {
|
||||
/// the actual data:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(discriminant_value)]
|
||||
/// use std::mem;
|
||||
///
|
||||
/// enum Foo { A(&'static str), B(i32), C(i32) }
|
||||
@ -777,7 +776,7 @@ impl<T> fmt::Debug for Discriminant<T> {
|
||||
/// assert!(mem::discriminant(&Foo::B(1)) == mem::discriminant(&Foo::B(2)));
|
||||
/// assert!(mem::discriminant(&Foo::B(3)) != mem::discriminant(&Foo::C(3)));
|
||||
/// ```
|
||||
#[unstable(feature = "discriminant_value", reason = "recently added, follows RFC", issue = "24263")]
|
||||
#[stable(feature = "discriminant_value", since = "1.22.0")]
|
||||
pub fn discriminant<T>(v: &T) -> Discriminant<T> {
|
||||
unsafe {
|
||||
Discriminant(intrinsics::discriminant_value(v), PhantomData)
|
||||
|
@ -24,7 +24,6 @@
|
||||
#![feature(conservative_impl_trait)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(discriminant_value)]
|
||||
#![feature(i128_type)]
|
||||
#![cfg_attr(windows, feature(libc))]
|
||||
#![feature(never_type)]
|
||||
@ -34,7 +33,6 @@
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(specialization)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(discriminant_value)]
|
||||
#![feature(trace_macros)]
|
||||
#![feature(test)]
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
#![feature(unsize)]
|
||||
#![feature(i128_type)]
|
||||
#![feature(conservative_impl_trait)]
|
||||
#![feature(discriminant_value)]
|
||||
#![feature(specialization)]
|
||||
|
||||
#![cfg_attr(unix, feature(libc))]
|
||||
|
@ -21,7 +21,6 @@
|
||||
#![feature(quote)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(specialization)]
|
||||
#![feature(discriminant_value)]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
#[macro_use]
|
||||
|
@ -8,8 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(discriminant_value)]
|
||||
|
||||
use std::mem;
|
||||
|
||||
enum ADT {
|
||||
|
Loading…
Reference in New Issue
Block a user