Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/utils.rs')
-rw-r--r--crates/hir-ty/src/utils.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/crates/hir-ty/src/utils.rs b/crates/hir-ty/src/utils.rs
index 681d087ede..3636580630 100644
--- a/crates/hir-ty/src/utils.rs
+++ b/crates/hir-ty/src/utils.rs
@@ -1,7 +1,7 @@
//! Helper functions for working with def, which don't need to be a separate
//! query, but can't be computed directly from `*Data` (ie, which need a `db`).
-use std::iter;
+use std::{hash::Hash, iter};
use base_db::CrateId;
use chalk_ir::{
@@ -20,7 +20,8 @@ use hir_def::{
resolver::{HasResolver, TypeNs},
type_ref::{TraitBoundModifier, TypeRef},
ConstParamId, EnumId, EnumVariantId, FunctionId, GenericDefId, ItemContainerId,
- LocalEnumVariantId, Lookup, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId,
+ LocalEnumVariantId, Lookup, OpaqueInternableThing, TraitId, TypeAliasId, TypeOrConstParamId,
+ TypeParamId,
};
use hir_expand::name::Name;
use intern::Interned;
@@ -464,3 +465,28 @@ pub(crate) fn detect_variant_from_bytes<'a>(
};
Some((var_id, var_layout))
}
+
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub(crate) struct InTypeConstIdMetadata(pub(crate) Ty);
+
+impl OpaqueInternableThing for InTypeConstIdMetadata {
+ fn dyn_hash(&self, mut state: &mut dyn std::hash::Hasher) {
+ self.hash(&mut state);
+ }
+
+ fn dyn_eq(&self, other: &dyn OpaqueInternableThing) -> bool {
+ other.as_any().downcast_ref::<Self>().map_or(false, |x| self == x)
+ }
+
+ fn dyn_clone(&self) -> Box<dyn OpaqueInternableThing> {
+ Box::new(self.clone())
+ }
+
+ fn as_any(&self) -> &dyn std::any::Any {
+ self
+ }
+
+ fn box_any(&self) -> Box<dyn std::any::Any> {
+ Box::new(self.clone())
+ }
+}