Use TypeAliasId in Ty, pt 1
This commit is contained in:
parent
3e32ac4f86
commit
6d2ec8765d
@ -17,7 +17,10 @@ use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
use std::{fmt, iter, mem};
|
||||
|
||||
use hir_def::{generics::GenericParams, AdtId, DefWithBodyId, GenericDefId};
|
||||
use hir_def::{
|
||||
generics::GenericParams, AdtId, ContainerId, DefWithBodyId, GenericDefId, HasModule, Lookup,
|
||||
TypeAliasId,
|
||||
};
|
||||
use ra_db::{impl_intern_key, salsa};
|
||||
|
||||
use crate::{
|
||||
@ -107,7 +110,7 @@ pub enum TypeCtor {
|
||||
/// when we have tried to normalize a projection like `T::Item` but
|
||||
/// couldn't find a better representation. In that case, we generate
|
||||
/// an **application type** like `(Iterator::Item)<T>`.
|
||||
AssociatedType(TypeAlias),
|
||||
AssociatedType(TypeAliasId),
|
||||
|
||||
/// The type of a specific closure.
|
||||
///
|
||||
@ -147,7 +150,7 @@ impl TypeCtor {
|
||||
generic_params.count_params_including_parent()
|
||||
}
|
||||
TypeCtor::AssociatedType(type_alias) => {
|
||||
let generic_params = db.generic_params(type_alias.id.into());
|
||||
let generic_params = db.generic_params(type_alias.into());
|
||||
generic_params.count_params_including_parent()
|
||||
}
|
||||
TypeCtor::FnPtr { num_args } => num_args as usize + 1,
|
||||
@ -173,7 +176,9 @@ impl TypeCtor {
|
||||
TypeCtor::Closure { .. } => None,
|
||||
TypeCtor::Adt(adt) => adt.krate(db),
|
||||
TypeCtor::FnDef(callable) => Some(callable.krate(db).into()),
|
||||
TypeCtor::AssociatedType(type_alias) => type_alias.krate(db),
|
||||
TypeCtor::AssociatedType(type_alias) => {
|
||||
Some(type_alias.lookup(db).module(db).krate.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +199,7 @@ impl TypeCtor {
|
||||
| TypeCtor::Closure { .. } => None,
|
||||
TypeCtor::Adt(adt) => Some(adt.into()),
|
||||
TypeCtor::FnDef(callable) => Some(callable.into()),
|
||||
TypeCtor::AssociatedType(type_alias) => Some(type_alias.id.into()),
|
||||
TypeCtor::AssociatedType(type_alias) => Some(type_alias.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -896,11 +901,12 @@ impl HirDisplay for ApplicationTy {
|
||||
}
|
||||
}
|
||||
TypeCtor::AssociatedType(type_alias) => {
|
||||
let trait_name = type_alias
|
||||
.parent_trait(f.db)
|
||||
.and_then(|t| t.name(f.db))
|
||||
.unwrap_or_else(Name::missing);
|
||||
let name = type_alias.name(f.db);
|
||||
let trait_ = match type_alias.lookup(f.db).container {
|
||||
ContainerId::TraitId(it) => it,
|
||||
_ => panic!("not an associated type"),
|
||||
};
|
||||
let trait_name = f.db.trait_data(trait_).name.clone().unwrap_or_else(Name::missing);
|
||||
let name = f.db.type_alias_data(type_alias).name.clone();
|
||||
write!(f, "{}::{}", trait_name, name)?;
|
||||
if self.parameters.len() > 0 {
|
||||
write!(f, "<")?;
|
||||
|
@ -9,7 +9,7 @@ use chalk_ir::{
|
||||
};
|
||||
use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
|
||||
|
||||
use hir_def::{lang_item::LangItemTarget, GenericDefId};
|
||||
use hir_def::{lang_item::LangItemTarget, GenericDefId, TypeAliasId};
|
||||
use hir_expand::name;
|
||||
|
||||
use ra_db::salsa::{InternId, InternKey};
|
||||
@ -215,6 +215,18 @@ impl ToChalk for TypeAlias {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToChalk for TypeAliasId {
|
||||
type Chalk = chalk_ir::TypeId;
|
||||
|
||||
fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TypeId {
|
||||
chalk_ir::TypeId(id_to_chalk(self))
|
||||
}
|
||||
|
||||
fn from_chalk(_db: &impl HirDatabase, type_alias_id: chalk_ir::TypeId) -> TypeAliasId {
|
||||
id_from_chalk(type_alias_id.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToChalk for AssocTyValue {
|
||||
type Chalk = chalk_rust_ir::AssociatedTyValueId;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user