diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 8a184de71..388530f31 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -19,13 +19,13 @@ use std::{fmt, iter, mem}; | |||
19 | 19 | ||
20 | use hir_def::{ | 20 | use hir_def::{ |
21 | generics::GenericParams, AdtId, ContainerId, DefWithBodyId, GenericDefId, HasModule, Lookup, | 21 | generics::GenericParams, AdtId, ContainerId, DefWithBodyId, GenericDefId, HasModule, Lookup, |
22 | TypeAliasId, | 22 | TraitId, TypeAliasId, |
23 | }; | 23 | }; |
24 | use ra_db::{impl_intern_key, salsa}; | 24 | use ra_db::{impl_intern_key, salsa}; |
25 | 25 | ||
26 | use crate::{ | 26 | use crate::{ |
27 | db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, FloatTy, IntTy, Mutability, | 27 | db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, FloatTy, IntTy, Mutability, |
28 | Name, Trait, TypeAlias, Uncertain, | 28 | Name, Trait, Uncertain, |
29 | }; | 29 | }; |
30 | use display::{HirDisplay, HirFormatter}; | 30 | use display::{HirDisplay, HirFormatter}; |
31 | 31 | ||
@@ -218,18 +218,19 @@ pub struct ApplicationTy { | |||
218 | /// trait and all its parameters are fully known. | 218 | /// trait and all its parameters are fully known. |
219 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 219 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
220 | pub struct ProjectionTy { | 220 | pub struct ProjectionTy { |
221 | pub associated_ty: TypeAlias, | 221 | pub associated_ty: TypeAliasId, |
222 | pub parameters: Substs, | 222 | pub parameters: Substs, |
223 | } | 223 | } |
224 | 224 | ||
225 | impl ProjectionTy { | 225 | impl ProjectionTy { |
226 | pub fn trait_ref(&self, db: &impl HirDatabase) -> TraitRef { | 226 | pub fn trait_ref(&self, db: &impl HirDatabase) -> TraitRef { |
227 | TraitRef { | 227 | TraitRef { trait_: self.trait_(db).into(), substs: self.parameters.clone() } |
228 | trait_: self | 228 | } |
229 | .associated_ty | 229 | |
230 | .parent_trait(db) | 230 | fn trait_(&self, db: &impl HirDatabase) -> TraitId { |
231 | .expect("projection ty without parent trait"), | 231 | match self.associated_ty.lookup(db).container { |
232 | substs: self.parameters.clone(), | 232 | ContainerId::TraitId(it) => it, |
233 | _ => panic!("projection ty without parent trait"), | ||
233 | } | 234 | } |
234 | } | 235 | } |
235 | } | 236 | } |
@@ -933,18 +934,15 @@ impl HirDisplay for ProjectionTy { | |||
933 | return write!(f, "…"); | 934 | return write!(f, "…"); |
934 | } | 935 | } |
935 | 936 | ||
936 | let trait_name = self | 937 | let trait_name = |
937 | .associated_ty | 938 | f.db.trait_data(self.trait_(f.db)).name.clone().unwrap_or_else(Name::missing); |
938 | .parent_trait(f.db) | ||
939 | .and_then(|t| t.name(f.db)) | ||
940 | .unwrap_or_else(Name::missing); | ||
941 | write!(f, "<{} as {}", self.parameters[0].display(f.db), trait_name,)?; | 939 | write!(f, "<{} as {}", self.parameters[0].display(f.db), trait_name,)?; |
942 | if self.parameters.len() > 1 { | 940 | if self.parameters.len() > 1 { |
943 | write!(f, "<")?; | 941 | write!(f, "<")?; |
944 | f.write_joined(&self.parameters[1..], ", ")?; | 942 | f.write_joined(&self.parameters[1..], ", ")?; |
945 | write!(f, ">")?; | 943 | write!(f, ">")?; |
946 | } | 944 | } |
947 | write!(f, ">::{}", self.associated_ty.name(f.db))?; | 945 | write!(f, ">::{}", f.db.type_alias_data(self.associated_ty).name)?; |
948 | Ok(()) | 946 | Ok(()) |
949 | } | 947 | } |
950 | } | 948 | } |
@@ -1007,7 +1005,10 @@ impl HirDisplay for Ty { | |||
1007 | write!(f, "<")?; | 1005 | write!(f, "<")?; |
1008 | angle_open = true; | 1006 | angle_open = true; |
1009 | } | 1007 | } |
1010 | let name = projection_pred.projection_ty.associated_ty.name(f.db); | 1008 | let name = |
1009 | f.db.type_alias_data(projection_pred.projection_ty.associated_ty) | ||
1010 | .name | ||
1011 | .clone(); | ||
1011 | write!(f, "{} = ", name)?; | 1012 | write!(f, "{} = ", name)?; |
1012 | projection_pred.ty.hir_fmt(f)?; | 1013 | projection_pred.ty.hir_fmt(f)?; |
1013 | } | 1014 | } |
@@ -1083,7 +1084,7 @@ impl HirDisplay for GenericPredicate { | |||
1083 | write!( | 1084 | write!( |
1084 | f, | 1085 | f, |
1085 | ">::{} = {}", | 1086 | ">::{} = {}", |
1086 | projection_pred.projection_ty.associated_ty.name(f.db), | 1087 | f.db.type_alias_data(projection_pred.projection_ty.associated_ty).name, |
1087 | projection_pred.ty.display(f.db) | 1088 | projection_pred.ty.display(f.db) |
1088 | )?; | 1089 | )?; |
1089 | } | 1090 | } |