about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2023-04-11 19:21:43 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2023-04-11 19:33:33 +0000
commitf028636b1aec09366973468e8c347c1cf8291561 (patch)
treefc31391de6080c1c147eae61a641ae049f5648c7 /compiler/rustc_data_structures/src
parentc738dcc284c17addbc0a311c29b4ecaaf2fcfbaa (diff)
Sprinkle some whitespace & uses
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/tagged_ptr.rs16
-rw-r--r--compiler/rustc_data_structures/src/tagged_ptr/copy.rs15
2 files changed, 25 insertions, 6 deletions
diff --git a/compiler/rustc_data_structures/src/tagged_ptr.rs b/compiler/rustc_data_structures/src/tagged_ptr.rs
index c96d7835b2b..e69a11dae0a 100644
--- a/compiler/rustc_data_structures/src/tagged_ptr.rs
+++ b/compiler/rustc_data_structures/src/tagged_ptr.rs
@@ -13,7 +13,7 @@
 //! The tag must implement the `Tag` trait. We assert that the tag and `Pointer`
 //! are compatible at compile time.
 
-use std::mem::ManuallyDrop;
+use std::mem::{self, ManuallyDrop};
 use std::ops::Deref;
 use std::rc::Rc;
 use std::sync::Arc;
@@ -104,14 +104,17 @@ pub unsafe trait Tag: Copy {
 
 unsafe impl<T> Pointer for Box<T> {
     const BITS: usize = bits_for::<Self::Target>();
+
     #[inline]
     fn into_usize(self) -> usize {
         Box::into_raw(self) as usize
     }
+
     #[inline]
     unsafe fn from_usize(ptr: usize) -> Self {
         Box::from_raw(ptr as *mut T)
     }
+
     unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R {
         let raw = ManuallyDrop::new(Self::from_usize(ptr));
         f(&raw)
@@ -120,14 +123,17 @@ unsafe impl<T> Pointer for Box<T> {
 
 unsafe impl<T> Pointer for Rc<T> {
     const BITS: usize = bits_for::<Self::Target>();
+
     #[inline]
     fn into_usize(self) -> usize {
         Rc::into_raw(self) as usize
     }
+
     #[inline]
     unsafe fn from_usize(ptr: usize) -> Self {
         Rc::from_raw(ptr as *const T)
     }
+
     unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R {
         let raw = ManuallyDrop::new(Self::from_usize(ptr));
         f(&raw)
@@ -136,14 +142,17 @@ unsafe impl<T> Pointer for Rc<T> {
 
 unsafe impl<T> Pointer for Arc<T> {
     const BITS: usize = bits_for::<Self::Target>();
+
     #[inline]
     fn into_usize(self) -> usize {
         Arc::into_raw(self) as usize
     }
+
     #[inline]
     unsafe fn from_usize(ptr: usize) -> Self {
         Arc::from_raw(ptr as *const T)
     }
+
     unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R {
         let raw = ManuallyDrop::new(Self::from_usize(ptr));
         f(&raw)
@@ -152,14 +161,17 @@ unsafe impl<T> Pointer for Arc<T> {
 
 unsafe impl<'a, T: 'a> Pointer for &'a T {
     const BITS: usize = bits_for::<Self::Target>();
+
     #[inline]
     fn into_usize(self) -> usize {
         self as *const T as usize
     }
+
     #[inline]
     unsafe fn from_usize(ptr: usize) -> Self {
         &*(ptr as *const T)
     }
+
     unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R {
         f(&*(&ptr as *const usize as *const Self))
     }
@@ -183,7 +195,7 @@ unsafe impl<'a, T: 'a> Pointer for &'a mut T {
 /// Returns the number of bits available for use for tags in a pointer to `T`
 /// (this is based on `T`'s alignment).
 pub const fn bits_for<T>() -> usize {
-    let bits = std::mem::align_of::<T>().trailing_zeros();
+    let bits = mem::align_of::<T>().trailing_zeros();
 
     // This is a replacement for `.try_into().unwrap()` unavailable in `const`
     // (it's fine to make an assert here, since this is only called in compile time)
diff --git a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs
index e1d3e0bd35a..d0c2b914584 100644
--- a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs
+++ b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs
@@ -3,6 +3,7 @@ use crate::stable_hasher::{HashStable, StableHasher};
 use std::fmt;
 use std::marker::PhantomData;
 use std::num::NonZeroUsize;
+use std::ops::{Deref, DerefMut};
 
 /// A `Copy` TaggedPtr.
 ///
@@ -73,6 +74,7 @@ where
     pub(super) fn pointer_raw(&self) -> usize {
         self.packed.get() << T::BITS
     }
+
     pub fn pointer(self) -> P
     where
         P: Copy,
@@ -83,21 +85,25 @@ where
         // P: Copy
         unsafe { P::from_usize(self.pointer_raw()) }
     }
+
     pub fn pointer_ref(&self) -> &P::Target {
         // SAFETY: pointer_raw returns the original pointer
         unsafe { std::mem::transmute_copy(&self.pointer_raw()) }
     }
+
     pub fn pointer_mut(&mut self) -> &mut P::Target
     where
-        P: std::ops::DerefMut,
+        P: DerefMut,
     {
         // SAFETY: pointer_raw returns the original pointer
         unsafe { std::mem::transmute_copy(&self.pointer_raw()) }
     }
+
     #[inline]
     pub fn tag(&self) -> T {
         unsafe { T::from_usize(self.packed.get() >> Self::TAG_BIT_SHIFT) }
     }
+
     #[inline]
     pub fn set_tag(&mut self, tag: T) {
         let mut packed = self.packed.get();
@@ -109,20 +115,21 @@ where
     }
 }
 
-impl<P, T, const COMPARE_PACKED: bool> std::ops::Deref for CopyTaggedPtr<P, T, COMPARE_PACKED>
+impl<P, T, const COMPARE_PACKED: bool> Deref for CopyTaggedPtr<P, T, COMPARE_PACKED>
 where
     P: Pointer,
     T: Tag,
 {
     type Target = P::Target;
+
     fn deref(&self) -> &Self::Target {
         self.pointer_ref()
     }
 }
 
-impl<P, T, const COMPARE_PACKED: bool> std::ops::DerefMut for CopyTaggedPtr<P, T, COMPARE_PACKED>
+impl<P, T, const COMPARE_PACKED: bool> DerefMut for CopyTaggedPtr<P, T, COMPARE_PACKED>
 where
-    P: Pointer + std::ops::DerefMut,
+    P: Pointer + DerefMut,
     T: Tag,
 {
     fn deref_mut(&mut self) -> &mut Self::Target {