Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stabilize mem::discriminant (closes #24263) #44263

Merged
merged 1 commit into from Sep 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/libcore/mem.rs
Expand Up @@ -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")
Expand All @@ -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) }
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/lib.rs
Expand Up @@ -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)]
Expand All @@ -34,7 +33,6 @@
#![feature(slice_patterns)]
#![feature(specialization)]
#![feature(unboxed_closures)]
#![feature(discriminant_value)]
#![feature(trace_macros)]
#![feature(test)]

Expand Down
1 change: 0 additions & 1 deletion src/librustc_data_structures/lib.rs
Expand Up @@ -29,7 +29,6 @@
#![feature(unsize)]
#![feature(i128_type)]
#![feature(conservative_impl_trait)]
#![feature(discriminant_value)]
#![feature(specialization)]

#![cfg_attr(unix, feature(libc))]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_metadata/lib.rs
Expand Up @@ -21,7 +21,6 @@
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(specialization)]
#![feature(discriminant_value)]
#![feature(rustc_private)]

#[macro_use]
Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/discriminant_value-wrapper.rs
Expand Up @@ -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 {
Expand Down