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.rs | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/crates/hir-ty/src/next_solver/def_id.rs b/crates/hir-ty/src/next_solver/def_id.rs index 542eca3ded..41b00b67cd 100644 --- a/crates/hir-ty/src/next_solver/def_id.rs +++ b/crates/hir-ty/src/next_solver/def_id.rs @@ -1,9 +1,9 @@ //! Definition of `SolverDefId` use hir_def::{ - AdtId, AnonConstId, AttrDefId, BuiltinDeriveImplId, CallableDefId, ConstId, DefWithBodyId, - EnumId, EnumVariantId, ExpressionStoreOwnerId, FunctionId, GeneralConstId, GenericDefId, - ImplId, StaticId, StructId, TraitId, TypeAliasId, UnionId, VariantId, + AdtId, AttrDefId, BuiltinDeriveImplId, CallableDefId, ConstId, DefWithBodyId, EnumId, + EnumVariantId, ExpressionStoreOwnerId, FunctionId, GenericDefId, ImplId, StaticId, StructId, + TraitId, TypeAliasId, UnionId, VariantId, signatures::{ ConstSignature, EnumSignature, FunctionSignature, StaticSignature, StructSignature, TraitSignature, TypeAliasSignature, UnionSignature, @@ -12,8 +12,12 @@ use hir_def::{ use rustc_type_ir::inherent; use stdx::impl_from; -use crate::db::{ - InternedClosureId, InternedCoroutineClosureId, InternedCoroutineId, InternedOpaqueTyId, +use crate::{ + InferBodyId, + db::{ + AnonConstId, GeneralConstId, InternedClosureId, InternedCoroutineClosureId, + InternedCoroutineId, InternedOpaqueTyId, + }, }; use super::DbInterner; @@ -173,6 +177,16 @@ impl From<DefWithBodyId> for SolverDefId { } } +impl From<InferBodyId> for SolverDefId { + #[inline] + fn from(value: InferBodyId) -> Self { + match value { + InferBodyId::DefWithBodyId(id) => id.into(), + InferBodyId::AnonConstId(id) => id.into(), + } + } +} + impl From<VariantId> for SolverDefId { #[inline] fn from(value: VariantId) -> Self { @@ -246,6 +260,32 @@ impl TryFrom<SolverDefId> for DefWithBodyId { } } +impl TryFrom<SolverDefId> for InferBodyId { + type Error = (); + + #[inline] + fn try_from(value: SolverDefId) -> Result<Self, Self::Error> { + let id = match value { + SolverDefId::ConstId(id) => id.into(), + SolverDefId::FunctionId(id) => id.into(), + SolverDefId::StaticId(id) => id.into(), + SolverDefId::EnumVariantId(id) | SolverDefId::Ctor(Ctor::Enum(id)) => id.into(), + SolverDefId::AnonConstId(id) => id.into(), + SolverDefId::InternedOpaqueTyId(_) + | SolverDefId::TraitId(_) + | SolverDefId::TypeAliasId(_) + | SolverDefId::ImplId(_) + | SolverDefId::BuiltinDeriveImplId(_) + | SolverDefId::InternedClosureId(_) + | SolverDefId::InternedCoroutineId(_) + | SolverDefId::InternedCoroutineClosureId(_) + | SolverDefId::Ctor(Ctor::Struct(_)) + | SolverDefId::AdtId(_) => return Err(()), + }; + Ok(id) + } +} + impl TryFrom<SolverDefId> for GenericDefId { type Error = (); |