about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2023-04-12 11:50:45 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2023-04-12 11:50:45 +0000
commit6f64ae3fbcf7a353537d250f91981ac336e12880 (patch)
tree9b355fb937543ced87ffeb2565406e08d70e86e7 /compiler
parent3df9a7bde32e7ae9fab45024fd38db827531c48d (diff)
downloadrust-6f64ae3fbcf7a353537d250f91981ac336e12880.tar.gz
rust-6f64ae3fbcf7a353537d250f91981ac336e12880.zip
Move code around
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_data_structures/src/tagged_ptr/copy.rs77
-rw-r--r--compiler/rustc_data_structures/src/tagged_ptr/drop.rs36
2 files changed, 57 insertions, 56 deletions
diff --git a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs
index edf429abfe9..90500b2de89 100644
--- a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs
+++ b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs
@@ -1,6 +1,7 @@
 use super::{Pointer, Tag};
 use crate::stable_hasher::{HashStable, StableHasher};
 use std::fmt;
+use std::hash::{Hash, Hasher};
 use std::marker::PhantomData;
 use std::mem::ManuallyDrop;
 use std::num::NonZeroUsize;
@@ -24,25 +25,6 @@ where
     tag_ghost: PhantomData<T>,
 }
 
-impl<P, T, const CP: bool> Copy for CopyTaggedPtr<P, T, CP>
-where
-    P: Pointer,
-    T: Tag,
-    P: Copy,
-{
-}
-
-impl<P, T, const CP: bool> Clone for CopyTaggedPtr<P, T, CP>
-where
-    P: Pointer,
-    T: Tag,
-    P: Copy,
-{
-    fn clone(&self) -> Self {
-        *self
-    }
-}
-
 // We pack the tag into the *upper* bits of the pointer to ease retrieval of the
 // value; a left shift is a multiplication and those are embeddable in
 // instruction encoding.
@@ -55,6 +37,27 @@ where
         Self { packed: Self::pack(P::into_ptr(pointer), tag), tag_ghost: PhantomData }
     }
 
+    pub fn pointer(self) -> P
+    where
+        P: Copy,
+    {
+        // SAFETY: pointer_raw returns the original pointer
+        //
+        // Note that this isn't going to double-drop or anything because we have
+        // P: Copy
+        unsafe { P::from_ptr(self.pointer_raw()) }
+    }
+
+    #[inline]
+    pub fn tag(&self) -> T {
+        unsafe { T::from_usize(self.packed.addr().get() >> Self::TAG_BIT_SHIFT) }
+    }
+
+    #[inline]
+    pub fn set_tag(&mut self, tag: T) {
+        self.packed = Self::pack(self.pointer_raw(), tag);
+    }
+
     const TAG_BIT_SHIFT: usize = usize::BITS as usize - T::BITS;
     const ASSERTION: () = { assert!(T::BITS <= P::BITS) };
 
@@ -103,26 +106,22 @@ where
         let ptr = unsafe { ManuallyDrop::new(P::from_ptr(self.pointer_raw())) };
         f(&ptr)
     }
+}
 
-    pub fn pointer(self) -> P
-    where
-        P: Copy,
-    {
-        // SAFETY: pointer_raw returns the original pointer
-        //
-        // Note that this isn't going to double-drop or anything because we have
-        // P: Copy
-        unsafe { P::from_ptr(self.pointer_raw()) }
-    }
-
-    #[inline]
-    pub fn tag(&self) -> T {
-        unsafe { T::from_usize(self.packed.addr().get() >> Self::TAG_BIT_SHIFT) }
-    }
+impl<P, T, const CP: bool> Copy for CopyTaggedPtr<P, T, CP>
+where
+    P: Pointer + Copy,
+    T: Tag,
+{
+}
 
-    #[inline]
-    pub fn set_tag(&mut self, tag: T) {
-        self.packed = Self::pack(self.pointer_raw(), tag);
+impl<P, T, const CP: bool> Clone for CopyTaggedPtr<P, T, CP>
+where
+    P: Pointer + Copy,
+    T: Tag,
+{
+    fn clone(&self) -> Self {
+        *self
     }
 }
 
@@ -184,12 +183,12 @@ where
 {
 }
 
-impl<P, T> std::hash::Hash for CopyTaggedPtr<P, T, true>
+impl<P, T> Hash for CopyTaggedPtr<P, T, true>
 where
     P: Pointer,
     T: Tag,
 {
-    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
+    fn hash<H: Hasher>(&self, state: &mut H) {
         self.packed.hash(state);
     }
 }
diff --git a/compiler/rustc_data_structures/src/tagged_ptr/drop.rs b/compiler/rustc_data_structures/src/tagged_ptr/drop.rs
index a722a0f1f32..60f3e1d2461 100644
--- a/compiler/rustc_data_structures/src/tagged_ptr/drop.rs
+++ b/compiler/rustc_data_structures/src/tagged_ptr/drop.rs
@@ -1,4 +1,6 @@
 use std::fmt;
+use std::hash::{Hash, Hasher};
+use std::ops::{Deref, DerefMut};
 
 use super::CopyTaggedPtr;
 use super::{Pointer, Tag};
@@ -17,18 +19,6 @@ where
     raw: CopyTaggedPtr<P, T, COMPARE_PACKED>,
 }
 
-impl<P, T, const CP: bool> Clone for TaggedPtr<P, T, CP>
-where
-    P: Pointer + Clone,
-    T: Tag,
-{
-    fn clone(&self) -> Self {
-        let ptr = self.raw.with_pointer_ref(P::clone);
-
-        Self::new(ptr, self.tag())
-    }
-}
-
 // We pack the tag into the *upper* bits of the pointer to ease retrieval of the
 // value; a right shift is a multiplication and those are embeddable in
 // instruction encoding.
@@ -46,7 +36,19 @@ where
     }
 }
 
-impl<P, T, const CP: bool> std::ops::Deref for TaggedPtr<P, T, CP>
+impl<P, T, const CP: bool> Clone for TaggedPtr<P, T, CP>
+where
+    P: Pointer + Clone,
+    T: Tag,
+{
+    fn clone(&self) -> Self {
+        let ptr = self.raw.with_pointer_ref(P::clone);
+
+        Self::new(ptr, self.tag())
+    }
+}
+
+impl<P, T, const CP: bool> Deref for TaggedPtr<P, T, CP>
 where
     P: Pointer,
     T: Tag,
@@ -57,9 +59,9 @@ where
     }
 }
 
-impl<P, T, const CP: bool> std::ops::DerefMut for TaggedPtr<P, T, CP>
+impl<P, T, const CP: bool> DerefMut for TaggedPtr<P, T, CP>
 where
-    P: Pointer + std::ops::DerefMut,
+    P: Pointer + DerefMut,
     T: Tag,
 {
     fn deref_mut(&mut self) -> &mut Self::Target {
@@ -109,12 +111,12 @@ where
 {
 }
 
-impl<P, T> std::hash::Hash for TaggedPtr<P, T, true>
+impl<P, T> Hash for TaggedPtr<P, T, true>
 where
     P: Pointer,
     T: Tag,
 {
-    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
+    fn hash<H: Hasher>(&self, state: &mut H) {
         self.raw.hash(state);
     }
 }