@@ -17,7 +17,10 @@ use std::ops::Deref;
17
17
use std:: sync:: Arc ;
18
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
24
use ra_db:: { impl_intern_key, salsa} ;
22
25
23
26
use crate :: {
@@ -107,7 +110,7 @@ pub enum TypeCtor {
107
110
/// when we have tried to normalize a projection like `T::Item` but
108
111
/// couldn't find a better representation. In that case, we generate
109
112
/// an **application type** like `(Iterator::Item)<T>`.
110
- AssociatedType ( TypeAlias ) ,
113
+ AssociatedType ( TypeAliasId ) ,
111
114
112
115
/// The type of a specific closure.
113
116
///
@@ -147,7 +150,7 @@ impl TypeCtor {
147
150
generic_params. count_params_including_parent ( )
148
151
}
149
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
154
generic_params. count_params_including_parent ( )
152
155
}
153
156
TypeCtor :: FnPtr { num_args } => num_args as usize + 1 ,
@@ -173,7 +176,9 @@ impl TypeCtor {
173
176
TypeCtor :: Closure { .. } => None ,
174
177
TypeCtor :: Adt ( adt) => adt. krate ( db) ,
175
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
199
| TypeCtor :: Closure { .. } => None ,
195
200
TypeCtor :: Adt ( adt) => Some ( adt. into ( ) ) ,
196
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
903
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 ( ) ;
904
910
write ! ( f, "{}::{}" , trait_name, name) ?;
905
911
if self . parameters . len ( ) > 0 {
906
912
write ! ( f, "<" ) ?;
0 commit comments