diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 26 |
1 files changed, 16 insertions, 10 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, "<")?; |