From afd83e0686512ad2678a2b0bad3b1421692a28bf Mon Sep 17 00:00:00 2001 From: Jonas Schievink <jonasschievink@gmail.com> Date: Thu, 1 Apr 2021 22:24:40 +0200 Subject: [PATCH] Remove unnecessary region, relax `Sized` bounds --- crates/hir_def/src/intern.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/crates/hir_def/src/intern.rs b/crates/hir_def/src/intern.rs index 4d8fbd32494..18c8ab246d5 100644 --- a/crates/hir_def/src/intern.rs +++ b/crates/hir_def/src/intern.rs @@ -16,7 +16,7 @@ use rustc_hash::FxHasher; type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>; #[derive(Hash)] -pub struct Interned<T: Internable> { +pub struct Interned<T: Internable + ?Sized> { arc: Arc<T>, } @@ -52,7 +52,7 @@ impl<T: Internable> Interned<T> { } } -impl<T: Internable> Drop for Interned<T> { +impl<T: Internable + ?Sized> Drop for Interned<T> { fn drop(&mut self) { // When the last `Ref` is dropped, remove the object from the global map. if Arc::strong_count(&self.arc) == 2 { @@ -83,23 +83,23 @@ impl<T: Internable> Drop for Interned<T> { } /// Compares interned `Ref`s using pointer equality. -impl<T: Internable> PartialEq for Interned<T> { +impl<T: Internable + ?Sized> PartialEq for Interned<T> { #[inline] fn eq(&self, other: &Self) -> bool { Arc::ptr_eq(&self.arc, &other.arc) } } -impl<T: Internable> Eq for Interned<T> {} +impl<T: Internable + ?Sized> Eq for Interned<T> {} -impl<T: Internable> AsRef<T> for Interned<T> { +impl<T: Internable + ?Sized> AsRef<T> for Interned<T> { #[inline] fn as_ref(&self) -> &T { &self.arc } } -impl<T: Internable> Deref for Interned<T> { +impl<T: Internable + ?Sized> Deref for Interned<T> { type Target = T; #[inline] @@ -108,40 +108,38 @@ impl<T: Internable> Deref for Interned<T> { } } -impl<T: Internable> Clone for Interned<T> { +impl<T: Internable + ?Sized> Clone for Interned<T> { fn clone(&self) -> Self { Self { arc: self.arc.clone() } } } -impl<T: Debug + Internable> Debug for Interned<T> { +impl<T: Debug + Internable + ?Sized> Debug for Interned<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (*self.arc).fmt(f) } } -pub struct InternStorage<T> { +pub struct InternStorage<T: ?Sized> { map: OnceCell<InternMap<T>>, } -impl<T> InternStorage<T> { +impl<T: ?Sized> InternStorage<T> { pub const fn new() -> Self { Self { map: OnceCell::new() } } } -impl<T: Internable> InternStorage<T> { +impl<T: Internable + ?Sized> InternStorage<T> { fn get(&self) -> &InternMap<T> { self.map.get_or_init(DashMap::default) } } -pub trait Internable: Hash + Eq + Sized + 'static { +pub trait Internable: Hash + Eq + 'static { fn storage() -> &'static InternStorage<Self>; } -// region:`Internable` implementations - macro_rules! impl_internable { ( $($t:ty),+ $(,)? ) => { $( impl Internable for $t { @@ -154,5 +152,3 @@ macro_rules! impl_internable { } impl_internable!(crate::type_ref::TypeRef, crate::type_ref::TraitRef, crate::path::ModPath); - -// endregion