diff options
-rw-r--r-- | crates/ra_hir/src/ty.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 14 |
2 files changed, 29 insertions, 11 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index bac21732e..8a184de71 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -17,7 +17,10 @@ use std::ops::Deref; | |||
17 | use std::sync::Arc; | 17 | use std::sync::Arc; |
18 | use std::{fmt, iter, mem}; | 18 | use std::{fmt, iter, mem}; |
19 | 19 | ||
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 | }; | ||
21 | use ra_db::{impl_intern_key, salsa}; | 24 | use ra_db::{impl_intern_key, salsa}; |
22 | 25 | ||
23 | use crate::{ | 26 | use crate::{ |
@@ -107,7 +110,7 @@ pub enum TypeCtor { | |||
107 | /// when we have tried to normalize a projection like `T::Item` but | 110 | /// when we have tried to normalize a projection like `T::Item` but |
108 | /// couldn't find a better representation. In that case, we generate | 111 | /// couldn't find a better representation. In that case, we generate |
109 | /// an **application type** like `(Iterator::Item)<T>`. | 112 | /// an **application type** like `(Iterator::Item)<T>`. |
110 | AssociatedType(TypeAlias), | 113 | AssociatedType(TypeAliasId), |
111 | 114 | ||
112 | /// The type of a specific closure. | 115 | /// The type of a specific closure. |
113 | /// | 116 | /// |
@@ -147,7 +150,7 @@ impl TypeCtor { | |||
147 | generic_params.count_params_including_parent() | 150 | generic_params.count_params_including_parent() |
148 | } | 151 | } |
149 | TypeCtor::AssociatedType(type_alias) => { | 152 | 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()); |
151 | generic_params.count_params_including_parent() | 154 | generic_params.count_params_including_parent() |
152 | } | 155 | } |
153 | TypeCtor::FnPtr { num_args } => num_args as usize + 1, | 156 | TypeCtor::FnPtr { num_args } => num_args as usize + 1, |
@@ -173,7 +176,9 @@ impl TypeCtor { | |||
173 | TypeCtor::Closure { .. } => None, | 176 | TypeCtor::Closure { .. } => None, |
174 | TypeCtor::Adt(adt) => adt.krate(db), | 177 | TypeCtor::Adt(adt) => adt.krate(db), |
175 | TypeCtor::FnDef(callable) => Some(callable.krate(db).into()), | 178 | 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 | } | ||
177 | } | 182 | } |
178 | } | 183 | } |
179 | 184 | ||
@@ -194,7 +199,7 @@ impl TypeCtor { | |||
194 | | TypeCtor::Closure { .. } => None, | 199 | | TypeCtor::Closure { .. } => None, |
195 | TypeCtor::Adt(adt) => Some(adt.into()), | 200 | TypeCtor::Adt(adt) => Some(adt.into()), |
196 | TypeCtor::FnDef(callable) => Some(callable.into()), | 201 | 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()), |
198 | } | 203 | } |
199 | } | 204 | } |
200 | } | 205 | } |
@@ -896,11 +901,12 @@ impl HirDisplay for ApplicationTy { | |||
896 | } | 901 | } |
897 | } | 902 | } |
898 | TypeCtor::AssociatedType(type_alias) => { | 903 | TypeCtor::AssociatedType(type_alias) => { |
899 | let trait_name = type_alias | 904 | let trait_ = match type_alias.lookup(f.db).container { |
900 | .parent_trait(f.db) | 905 | ContainerId::TraitId(it) => it, |
901 | .and_then(|t| t.name(f.db)) | 906 | _ => panic!("not an associated type"), |
902 | .unwrap_or_else(Name::missing); | 907 | }; |
903 | let name = type_alias.name(f.db); | 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(); | ||
904 | write!(f, "{}::{}", trait_name, name)?; | 910 | write!(f, "{}::{}", trait_name, name)?; |
905 | if self.parameters.len() > 0 { | 911 | if self.parameters.len() > 0 { |
906 | write!(f, "<")?; | 912 | write!(f, "<")?; |
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 0272dd9ae..fd2f1b174 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -9,7 +9,7 @@ use chalk_ir::{ | |||
9 | }; | 9 | }; |
10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; | 10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; |
11 | 11 | ||
12 | use hir_def::{lang_item::LangItemTarget, GenericDefId}; | 12 | use hir_def::{lang_item::LangItemTarget, GenericDefId, TypeAliasId}; |
13 | use hir_expand::name; | 13 | use hir_expand::name; |
14 | 14 | ||
15 | use ra_db::salsa::{InternId, InternKey}; | 15 | use ra_db::salsa::{InternId, InternKey}; |
@@ -215,6 +215,18 @@ impl ToChalk for TypeAlias { | |||
215 | } | 215 | } |
216 | } | 216 | } |
217 | 217 | ||
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 | |||
218 | impl ToChalk for AssocTyValue { | 230 | impl ToChalk for AssocTyValue { |
219 | type Chalk = chalk_rust_ir::AssociatedTyValueId; | 231 | type Chalk = chalk_rust_ir::AssociatedTyValueId; |
220 | 232 | ||