Skip to content

Commit 8e55fa0

Browse files
Derive Eq, Ord, Hash for MaybeDangling
1 parent f5eca4f commit 8e55fa0

File tree

2 files changed

+3
-42
lines changed

2 files changed

+3
-42
lines changed

library/core/src/mem/manually_drop.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::cmp::Ordering;
2-
use crate::hash::{Hash, Hasher};
3-
use crate::marker::{Destruct, StructuralPartialEq};
1+
use crate::marker::Destruct;
42
use crate::mem::MaybeDangling;
53
use crate::ops::{Deref, DerefMut, DerefPure};
64
use crate::ptr;
@@ -155,7 +153,7 @@ use crate::ptr;
155153
/// [`MaybeUninit`]: crate::mem::MaybeUninit
156154
#[stable(feature = "manually_drop", since = "1.20.0")]
157155
#[lang = "manually_drop"]
158-
#[derive(Copy, Clone, Debug, Default)]
156+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
159157
#[repr(transparent)]
160158
#[rustc_pub_transparent]
161159
pub struct ManuallyDrop<T: ?Sized> {
@@ -289,37 +287,3 @@ impl<T: ?Sized> const DerefMut for ManuallyDrop<T> {
289287

290288
#[unstable(feature = "deref_pure_trait", issue = "87121")]
291289
unsafe impl<T: ?Sized> DerefPure for ManuallyDrop<T> {}
292-
293-
#[stable(feature = "manually_drop", since = "1.20.0")]
294-
impl<T: ?Sized + Eq> Eq for ManuallyDrop<T> {}
295-
296-
#[stable(feature = "manually_drop", since = "1.20.0")]
297-
impl<T: ?Sized + PartialEq> PartialEq for ManuallyDrop<T> {
298-
fn eq(&self, other: &Self) -> bool {
299-
self.value.as_ref().eq(other.value.as_ref())
300-
}
301-
}
302-
303-
#[stable(feature = "manually_drop", since = "1.20.0")]
304-
impl<T: ?Sized> StructuralPartialEq for ManuallyDrop<T> {}
305-
306-
#[stable(feature = "manually_drop", since = "1.20.0")]
307-
impl<T: ?Sized + Ord> Ord for ManuallyDrop<T> {
308-
fn cmp(&self, other: &Self) -> Ordering {
309-
self.value.as_ref().cmp(other.value.as_ref())
310-
}
311-
}
312-
313-
#[stable(feature = "manually_drop", since = "1.20.0")]
314-
impl<T: ?Sized + PartialOrd> PartialOrd for ManuallyDrop<T> {
315-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
316-
self.value.as_ref().partial_cmp(other.value.as_ref())
317-
}
318-
}
319-
320-
#[stable(feature = "manually_drop", since = "1.20.0")]
321-
impl<T: ?Sized + Hash> Hash for ManuallyDrop<T> {
322-
fn hash<H: Hasher>(&self, state: &mut H) {
323-
self.value.as_ref().hash(state);
324-
}
325-
}

library/core/src/mem/maybe_dangling.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![unstable(feature = "maybe_dangling", issue = "118166")]
22

3-
use crate::marker::StructuralPartialEq;
43
use crate::{mem, ptr};
54

65
/// Allows wrapped [references] and [boxes] to dangle.
@@ -69,7 +68,7 @@ use crate::{mem, ptr};
6968
/// [`ManuallyDrop`]: crate::mem::ManuallyDrop
7069
#[repr(transparent)]
7170
#[rustc_pub_transparent]
72-
#[derive(Debug, Copy, Clone, Default)]
71+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
7372
#[lang = "maybe_dangling"]
7473
pub struct MaybeDangling<P: ?Sized>(P);
7574

@@ -110,5 +109,3 @@ impl<P: ?Sized> MaybeDangling<P> {
110109
x
111110
}
112111
}
113-
114-
impl<T: ?Sized> StructuralPartialEq for MaybeDangling<T> {}

0 commit comments

Comments
 (0)