Skip to content

Commit 6d2ec87

Browse files
committed
Use TypeAliasId in Ty, pt 1
1 parent 3e32ac4 commit 6d2ec87

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

crates/ra_hir/src/ty.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ use std::ops::Deref;
1717
use std::sync::Arc;
1818
use std::{fmt, iter, mem};
1919

20-
use hir_def::{generics::GenericParams, AdtId, DefWithBodyId, GenericDefId};
20+
use hir_def::{
21+
generics::GenericParams, AdtId, ContainerId, DefWithBodyId, GenericDefId, HasModule, Lookup,
22+
TypeAliasId,
23+
};
2124
use ra_db::{impl_intern_key, salsa};
2225

2326
use crate::{
@@ -107,7 +110,7 @@ pub enum TypeCtor {
107110
/// when we have tried to normalize a projection like `T::Item` but
108111
/// couldn't find a better representation. In that case, we generate
109112
/// an **application type** like `(Iterator::Item)<T>`.
110-
AssociatedType(TypeAlias),
113+
AssociatedType(TypeAliasId),
111114

112115
/// The type of a specific closure.
113116
///
@@ -147,7 +150,7 @@ impl TypeCtor {
147150
generic_params.count_params_including_parent()
148151
}
149152
TypeCtor::AssociatedType(type_alias) => {
150-
let generic_params = db.generic_params(type_alias.id.into());
153+
let generic_params = db.generic_params(type_alias.into());
151154
generic_params.count_params_including_parent()
152155
}
153156
TypeCtor::FnPtr { num_args } => num_args as usize + 1,
@@ -173,7 +176,9 @@ impl TypeCtor {
173176
TypeCtor::Closure { .. } => None,
174177
TypeCtor::Adt(adt) => adt.krate(db),
175178
TypeCtor::FnDef(callable) => Some(callable.krate(db).into()),
176-
TypeCtor::AssociatedType(type_alias) => type_alias.krate(db),
179+
TypeCtor::AssociatedType(type_alias) => {
180+
Some(type_alias.lookup(db).module(db).krate.into())
181+
}
177182
}
178183
}
179184

@@ -194,7 +199,7 @@ impl TypeCtor {
194199
| TypeCtor::Closure { .. } => None,
195200
TypeCtor::Adt(adt) => Some(adt.into()),
196201
TypeCtor::FnDef(callable) => Some(callable.into()),
197-
TypeCtor::AssociatedType(type_alias) => Some(type_alias.id.into()),
202+
TypeCtor::AssociatedType(type_alias) => Some(type_alias.into()),
198203
}
199204
}
200205
}
@@ -896,11 +901,12 @@ impl HirDisplay for ApplicationTy {
896901
}
897902
}
898903
TypeCtor::AssociatedType(type_alias) => {
899-
let trait_name = type_alias
900-
.parent_trait(f.db)
901-
.and_then(|t| t.name(f.db))
902-
.unwrap_or_else(Name::missing);
903-
let name = type_alias.name(f.db);
904+
let trait_ = match type_alias.lookup(f.db).container {
905+
ContainerId::TraitId(it) => it,
906+
_ => panic!("not an associated type"),
907+
};
908+
let trait_name = f.db.trait_data(trait_).name.clone().unwrap_or_else(Name::missing);
909+
let name = f.db.type_alias_data(type_alias).name.clone();
904910
write!(f, "{}::{}", trait_name, name)?;
905911
if self.parameters.len() > 0 {
906912
write!(f, "<")?;

crates/ra_hir/src/ty/traits/chalk.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use chalk_ir::{
99
};
1010
use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
1111

12-
use hir_def::{lang_item::LangItemTarget, GenericDefId};
12+
use hir_def::{lang_item::LangItemTarget, GenericDefId, TypeAliasId};
1313
use hir_expand::name;
1414

1515
use ra_db::salsa::{InternId, InternKey};
@@ -215,6 +215,18 @@ impl ToChalk for TypeAlias {
215215
}
216216
}
217217

218+
impl ToChalk for TypeAliasId {
219+
type Chalk = chalk_ir::TypeId;
220+
221+
fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TypeId {
222+
chalk_ir::TypeId(id_to_chalk(self))
223+
}
224+
225+
fn from_chalk(_db: &impl HirDatabase, type_alias_id: chalk_ir::TypeId) -> TypeAliasId {
226+
id_from_chalk(type_alias_id.0)
227+
}
228+
}
229+
218230
impl ToChalk for AssocTyValue {
219231
type Chalk = chalk_rust_ir::AssociatedTyValueId;
220232

0 commit comments

Comments
 (0)