Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/next_solver/def_id.rs')
-rw-r--r--crates/hir-ty/src/next_solver/def_id.rs49
1 files changed, 47 insertions, 2 deletions
diff --git a/crates/hir-ty/src/next_solver/def_id.rs b/crates/hir-ty/src/next_solver/def_id.rs
index 77f21062b4..2c30922246 100644
--- a/crates/hir-ty/src/next_solver/def_id.rs
+++ b/crates/hir-ty/src/next_solver/def_id.rs
@@ -1,8 +1,9 @@
//! Definition of `SolverDefId`
use hir_def::{
- AdtId, CallableDefId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId,
- GeneralConstId, GenericDefId, ImplId, StaticId, StructId, TraitId, TypeAliasId, UnionId,
+ AdtId, AttrDefId, CallableDefId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId,
+ GeneralConstId, GenericDefId, HasModule, ImplId, ModuleId, StaticId, StructId, TraitId,
+ TypeAliasId, UnionId, db::DefDatabase,
};
use rustc_type_ir::inherent;
use stdx::impl_from;
@@ -154,6 +155,28 @@ impl From<DefWithBodyId> for SolverDefId {
}
}
+impl TryFrom<SolverDefId> for AttrDefId {
+ type Error = ();
+ #[inline]
+ fn try_from(value: SolverDefId) -> Result<Self, Self::Error> {
+ match value {
+ SolverDefId::AdtId(it) => Ok(it.into()),
+ SolverDefId::ConstId(it) => Ok(it.into()),
+ SolverDefId::FunctionId(it) => Ok(it.into()),
+ SolverDefId::ImplId(it) => Ok(it.into()),
+ SolverDefId::StaticId(it) => Ok(it.into()),
+ SolverDefId::TraitId(it) => Ok(it.into()),
+ SolverDefId::TypeAliasId(it) => Ok(it.into()),
+ SolverDefId::EnumVariantId(it) => Ok(it.into()),
+ SolverDefId::Ctor(Ctor::Struct(it)) => Ok(it.into()),
+ SolverDefId::Ctor(Ctor::Enum(it)) => Ok(it.into()),
+ SolverDefId::InternedClosureId(_)
+ | SolverDefId::InternedCoroutineId(_)
+ | SolverDefId::InternedOpaqueTyId(_) => Err(()),
+ }
+ }
+}
+
impl TryFrom<SolverDefId> for DefWithBodyId {
type Error = ();
@@ -218,6 +241,28 @@ impl SolverDefId {
}
}
+impl HasModule for SolverDefId {
+ fn module(&self, db: &dyn DefDatabase) -> ModuleId {
+ match *self {
+ SolverDefId::AdtId(id) => id.module(db),
+ SolverDefId::ConstId(id) => id.module(db),
+ SolverDefId::FunctionId(id) => id.module(db),
+ SolverDefId::ImplId(id) => id.module(db),
+ SolverDefId::StaticId(id) => id.module(db),
+ SolverDefId::TraitId(id) => id.module(db),
+ SolverDefId::TypeAliasId(id) => id.module(db),
+ SolverDefId::InternedClosureId(id) => id.loc(db).0.module(db),
+ SolverDefId::InternedCoroutineId(id) => id.loc(db).0.module(db),
+ SolverDefId::InternedOpaqueTyId(id) => match id.loc(db) {
+ crate::ImplTraitId::ReturnTypeImplTrait(owner, _) => owner.module(db),
+ crate::ImplTraitId::TypeAliasImplTrait(owner, _) => owner.module(db),
+ },
+ SolverDefId::Ctor(Ctor::Enum(id)) | SolverDefId::EnumVariantId(id) => id.module(db),
+ SolverDefId::Ctor(Ctor::Struct(id)) => id.module(db),
+ }
+ }
+}
+
impl<'db> inherent::DefId<DbInterner<'db>> for SolverDefId {
fn as_local(self) -> Option<SolverDefId> {
Some(self)