Skip to content

Commit

Permalink
remove const trait impl
Browse files Browse the repository at this point in the history
  • Loading branch information
SparrowLii committed Apr 23, 2023
1 parent 1435c15 commit f925ea0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#![feature(unwrap_infallible)]
#![feature(strict_provenance)]
#![feature(ptr_alignment_type)]
#![feature(const_ptr_as_ref)]
#![allow(rustc::default_hash_types)]
#![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)]
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pub use std::sync::OnceLock as OnceCell;

pub use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicUsize};

pub type MTRef<'a, T> = &'a T;
pub type MTLockRef<'a, T> = &'a MTLock<T>;

#[derive(Debug, Default)]
pub struct MTLock<T>(Lock<T>);
Expand Down Expand Up @@ -422,9 +422,10 @@ unsafe impl<T: DynSend> Send for FromDyn<T> {}
#[cfg(parallel_compiler)]
unsafe impl<T: DynSync> Sync for FromDyn<T> {}

impl<T> const std::ops::Deref for FromDyn<T> {
impl<T> std::ops::Deref for FromDyn<T> {
type Target = T;

#[inline(always)]
fn deref(&self) -> &Self::Target {
&self.0
}
Expand Down Expand Up @@ -564,23 +565,25 @@ pub struct LockGuard<'a, T> {
marker: PhantomData<&'a mut T>,
}

impl<T> const Deref for LockGuard<'_, T> {
impl<T> Deref for LockGuard<'_, T> {
type Target = T;

#[inline(always)]
fn deref(&self) -> &T {
unsafe { &*self.lock.data.get() }
}
}

impl<T> const DerefMut for LockGuard<'_, T> {
impl<T> DerefMut for LockGuard<'_, T> {
#[inline(always)]
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.lock.data.get() }
}
}

#[inline(never)]
unsafe fn unlock_mt<T>(guard: &mut LockGuard<'_, T>) {
guard.lock.mutex.unlock()
fn unlock_mt<T>(guard: &mut LockGuard<'_, T>) {
unsafe { guard.lock.mutex.unlock() }
}

impl<'a, T> Drop for LockGuard<'a, T> {
Expand All @@ -590,7 +593,7 @@ impl<'a, T> Drop for LockGuard<'a, T> {
debug_assert!(self.lock.borrow.get());
self.lock.borrow.set(false);
} else {
unsafe { unlock_mt(self) }
unlock_mt(self)
}
}
}
Expand Down

0 comments on commit f925ea0

Please sign in to comment.