Skip to content

Commit

Permalink
Auto merge of #44263 - durka:stabilize-discriminant, r=dtolnay
Browse files Browse the repository at this point in the history
stabilize mem::discriminant (closes #24263)
  • Loading branch information
bors committed Sep 3, 2017
2 parents 981ce7d + d516434 commit 0006d3e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
17 changes: 8 additions & 9 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 0006d3e

Please sign in to comment.