Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/mapping.rs')
-rw-r--r--crates/hir-ty/src/mapping.rs55
1 files changed, 30 insertions, 25 deletions
diff --git a/crates/hir-ty/src/mapping.rs b/crates/hir-ty/src/mapping.rs
index 9d3d2044c4..5125a38825 100644
--- a/crates/hir-ty/src/mapping.rs
+++ b/crates/hir-ty/src/mapping.rs
@@ -3,8 +3,6 @@
//! Chalk (in both directions); plus some helper functions for more specialized
//! conversions.
-use chalk_solve::rust_ir;
-
use hir_def::{LifetimeParamId, TraitId, TypeAliasId, TypeOrConstParamId};
use salsa::{
Id,
@@ -54,23 +52,6 @@ impl ToChalk for CallableDefId {
}
}
-pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId);
-
-impl ToChalk for TypeAliasAsValue {
- type Chalk = chalk_db::AssociatedTyValueId;
-
- fn to_chalk(self, _db: &dyn HirDatabase) -> chalk_db::AssociatedTyValueId {
- rust_ir::AssociatedTyValueId(self.0.as_id())
- }
-
- fn from_chalk(
- _db: &dyn HirDatabase,
- assoc_ty_value_id: chalk_db::AssociatedTyValueId,
- ) -> TypeAliasAsValue {
- TypeAliasAsValue(TypeAliasId::from_id(assoc_ty_value_id.0))
- }
-}
-
impl From<OpaqueTyId> for crate::db::InternedOpaqueTyId {
fn from(id: OpaqueTyId) -> Self {
FromId::from_id(id.0)
@@ -123,7 +104,10 @@ pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId {
FromId::from_id(id.0)
}
-pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> TypeOrConstParamId {
+pub fn from_placeholder_idx(
+ db: &dyn HirDatabase,
+ idx: PlaceholderIndex,
+) -> (TypeOrConstParamId, u32) {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
// SAFETY: We cannot really encapsulate this unfortunately, so just hope this is sound.
let interned_id =
@@ -131,15 +115,32 @@ pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> Type
interned_id.loc(db)
}
-pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeOrConstParamId) -> PlaceholderIndex {
- let interned_id = InternedTypeOrConstParamId::new(db, id);
+pub fn to_placeholder_idx(
+ db: &dyn HirDatabase,
+ id: TypeOrConstParamId,
+ idx: u32,
+) -> PlaceholderIndex {
+ let interned_id = InternedTypeOrConstParamId::new(db, (id, idx));
PlaceholderIndex {
ui: chalk_ir::UniverseIndex::ROOT,
idx: interned_id.as_id().index() as usize,
}
}
-pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> LifetimeParamId {
+pub fn to_placeholder_idx_no_index(
+ db: &dyn HirDatabase,
+ id: TypeOrConstParamId,
+) -> PlaceholderIndex {
+ let index = crate::generics::generics(db, id.parent)
+ .type_or_const_param_idx(id)
+ .expect("param not found");
+ to_placeholder_idx(db, id, index as u32)
+}
+
+pub fn lt_from_placeholder_idx(
+ db: &dyn HirDatabase,
+ idx: PlaceholderIndex,
+) -> (LifetimeParamId, u32) {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
// SAFETY: We cannot really encapsulate this unfortunately, so just hope this is sound.
let interned_id =
@@ -147,8 +148,12 @@ pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> L
interned_id.loc(db)
}
-pub fn lt_to_placeholder_idx(db: &dyn HirDatabase, id: LifetimeParamId) -> PlaceholderIndex {
- let interned_id = InternedLifetimeParamId::new(db, id);
+pub fn lt_to_placeholder_idx(
+ db: &dyn HirDatabase,
+ id: LifetimeParamId,
+ idx: u32,
+) -> PlaceholderIndex {
+ let interned_id = InternedLifetimeParamId::new(db, (id, idx));
PlaceholderIndex {
ui: chalk_ir::UniverseIndex::ROOT,
idx: interned_id.as_id().index() as usize,