aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/intern.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/crates/hir_def/src/intern.rs b/crates/hir_def/src/intern.rs
index 0d5419be5..abc304ef0 100644
--- a/crates/hir_def/src/intern.rs
+++ b/crates/hir_def/src/intern.rs
@@ -5,7 +5,7 @@
5use std::{ 5use std::{
6 collections::HashMap, 6 collections::HashMap,
7 fmt::{self, Debug}, 7 fmt::{self, Debug},
8 hash::{BuildHasherDefault, Hash}, 8 hash::{BuildHasherDefault, Hash, Hasher},
9 ops::Deref, 9 ops::Deref,
10 sync::Arc, 10 sync::Arc,
11}; 11};
@@ -20,7 +20,6 @@ type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>;
20type Guard<T> = 20type Guard<T> =
21 RwLockWriteGuard<'static, HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>>; 21 RwLockWriteGuard<'static, HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>>;
22 22
23#[derive(Hash)]
24pub struct Interned<T: Internable + ?Sized> { 23pub struct Interned<T: Internable + ?Sized> {
25 arc: Arc<T>, 24 arc: Arc<T>,
26} 25}
@@ -137,6 +136,13 @@ impl PartialEq for Interned<str> {
137 136
138impl Eq for Interned<str> {} 137impl Eq for Interned<str> {}
139 138
139impl<T: Internable + ?Sized> Hash for Interned<T> {
140 fn hash<H: Hasher>(&self, state: &mut H) {
141 // NOTE: Cast disposes vtable pointer / slice/str length.
142 state.write_usize(Arc::as_ptr(&self.arc) as *const () as usize)
143 }
144}
145
140impl<T: Internable + ?Sized> AsRef<T> for Interned<T> { 146impl<T: Internable + ?Sized> AsRef<T> for Interned<T> {
141 #[inline] 147 #[inline]
142 fn as_ref(&self) -> &T { 148 fn as_ref(&self) -> &T {