aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-01 21:24:40 +0100
committerJonas Schievink <[email protected]>2021-04-01 21:24:40 +0100
commitafd83e0686512ad2678a2b0bad3b1421692a28bf (patch)
treeb3c34e9c041821acbad8d2d4518d719165268bd7 /crates/hir_def/src
parent39d992ef559c9cd67551819a9d63ef52ef7b725f (diff)
Remove unnecessary region, relax `Sized` bounds
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/intern.rs28
1 files changed, 12 insertions, 16 deletions
diff --git a/crates/hir_def/src/intern.rs b/crates/hir_def/src/intern.rs
index 4d8fbd324..18c8ab246 100644
--- a/crates/hir_def/src/intern.rs
+++ b/crates/hir_def/src/intern.rs
@@ -16,7 +16,7 @@ use rustc_hash::FxHasher;
16type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>; 16type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>;
17 17
18#[derive(Hash)] 18#[derive(Hash)]
19pub struct Interned<T: Internable> { 19pub struct Interned<T: Internable + ?Sized> {
20 arc: Arc<T>, 20 arc: Arc<T>,
21} 21}
22 22
@@ -52,7 +52,7 @@ impl<T: Internable> Interned<T> {
52 } 52 }
53} 53}
54 54
55impl<T: Internable> Drop for Interned<T> { 55impl<T: Internable + ?Sized> Drop for Interned<T> {
56 fn drop(&mut self) { 56 fn drop(&mut self) {
57 // When the last `Ref` is dropped, remove the object from the global map. 57 // When the last `Ref` is dropped, remove the object from the global map.
58 if Arc::strong_count(&self.arc) == 2 { 58 if Arc::strong_count(&self.arc) == 2 {
@@ -83,23 +83,23 @@ impl<T: Internable> Drop for Interned<T> {
83} 83}
84 84
85/// Compares interned `Ref`s using pointer equality. 85/// Compares interned `Ref`s using pointer equality.
86impl<T: Internable> PartialEq for Interned<T> { 86impl<T: Internable + ?Sized> PartialEq for Interned<T> {
87 #[inline] 87 #[inline]
88 fn eq(&self, other: &Self) -> bool { 88 fn eq(&self, other: &Self) -> bool {
89 Arc::ptr_eq(&self.arc, &other.arc) 89 Arc::ptr_eq(&self.arc, &other.arc)
90 } 90 }
91} 91}
92 92
93impl<T: Internable> Eq for Interned<T> {} 93impl<T: Internable + ?Sized> Eq for Interned<T> {}
94 94
95impl<T: Internable> AsRef<T> for Interned<T> { 95impl<T: Internable + ?Sized> AsRef<T> for Interned<T> {
96 #[inline] 96 #[inline]
97 fn as_ref(&self) -> &T { 97 fn as_ref(&self) -> &T {
98 &self.arc 98 &self.arc
99 } 99 }
100} 100}
101 101
102impl<T: Internable> Deref for Interned<T> { 102impl<T: Internable + ?Sized> Deref for Interned<T> {
103 type Target = T; 103 type Target = T;
104 104
105 #[inline] 105 #[inline]
@@ -108,40 +108,38 @@ impl<T: Internable> Deref for Interned<T> {
108 } 108 }
109} 109}
110 110
111impl<T: Internable> Clone for Interned<T> { 111impl<T: Internable + ?Sized> Clone for Interned<T> {
112 fn clone(&self) -> Self { 112 fn clone(&self) -> Self {
113 Self { arc: self.arc.clone() } 113 Self { arc: self.arc.clone() }
114 } 114 }
115} 115}
116 116
117impl<T: Debug + Internable> Debug for Interned<T> { 117impl<T: Debug + Internable + ?Sized> Debug for Interned<T> {
118 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 118 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119 (*self.arc).fmt(f) 119 (*self.arc).fmt(f)
120 } 120 }
121} 121}
122 122
123pub struct InternStorage<T> { 123pub struct InternStorage<T: ?Sized> {
124 map: OnceCell<InternMap<T>>, 124 map: OnceCell<InternMap<T>>,
125} 125}
126 126
127impl<T> InternStorage<T> { 127impl<T: ?Sized> InternStorage<T> {
128 pub const fn new() -> Self { 128 pub const fn new() -> Self {
129 Self { map: OnceCell::new() } 129 Self { map: OnceCell::new() }
130 } 130 }
131} 131}
132 132
133impl<T: Internable> InternStorage<T> { 133impl<T: Internable + ?Sized> InternStorage<T> {
134 fn get(&self) -> &InternMap<T> { 134 fn get(&self) -> &InternMap<T> {
135 self.map.get_or_init(DashMap::default) 135 self.map.get_or_init(DashMap::default)
136 } 136 }
137} 137}
138 138
139pub trait Internable: Hash + Eq + Sized + 'static { 139pub trait Internable: Hash + Eq + 'static {
140 fn storage() -> &'static InternStorage<Self>; 140 fn storage() -> &'static InternStorage<Self>;
141} 141}
142 142
143// region:`Internable` implementations
144
145macro_rules! impl_internable { 143macro_rules! impl_internable {
146 ( $($t:ty),+ $(,)? ) => { $( 144 ( $($t:ty),+ $(,)? ) => { $(
147 impl Internable for $t { 145 impl Internable for $t {
@@ -154,5 +152,3 @@ macro_rules! impl_internable {
154} 152}
155 153
156impl_internable!(crate::type_ref::TypeRef, crate::type_ref::TraitRef, crate::path::ModPath); 154impl_internable!(crate::type_ref::TypeRef, crate::type_ref::TraitRef, crate::path::ModPath);
157
158// endregion