diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 2854631c6..ff041150b 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -311,7 +311,11 @@ impl StructField { | |||
311 | self.parent.variant_data(db).fields()[self.id].name.clone() | 311 | self.parent.variant_data(db).fields()[self.id].name.clone() |
312 | } | 312 | } |
313 | 313 | ||
314 | pub fn ty(&self, db: &impl HirDatabase) -> Type { | 314 | /// Returns the type as in the signature of the struct (i.e., with |
315 | /// placeholder types for type parameters). This is good for showing | ||
316 | /// signature help, but not so good to actually get the type of the field | ||
317 | /// when you actually have a variable of the struct. | ||
318 | pub fn signature_ty(&self, db: &impl HirDatabase) -> Type { | ||
315 | let var_id = self.parent.into(); | 319 | let var_id = self.parent.into(); |
316 | let generic_def_id: GenericDefId = match self.parent { | 320 | let generic_def_id: GenericDefId = match self.parent { |
317 | VariantDef::Struct(it) => it.id.into(), | 321 | VariantDef::Struct(it) => it.id.into(), |
@@ -485,6 +489,10 @@ impl Adt { | |||
485 | let subst = db.generic_defaults(self.into()); | 489 | let subst = db.generic_defaults(self.into()); |
486 | subst.iter().any(|ty| ty == &Ty::Unknown) | 490 | subst.iter().any(|ty| ty == &Ty::Unknown) |
487 | } | 491 | } |
492 | |||
493 | /// Turns this ADT into a type. Any type parameters of the ADT will be | ||
494 | /// turned into unknown types, which is good for e.g. finding the most | ||
495 | /// general set of completions, but will not look very nice when printed. | ||
488 | pub fn ty(self, db: &impl HirDatabase) -> Type { | 496 | pub fn ty(self, db: &impl HirDatabase) -> Type { |
489 | let id = AdtId::from(self); | 497 | let id = AdtId::from(self); |
490 | Type::from_def(db, id.module(db).krate, id) | 498 | Type::from_def(db, id.module(db).krate, id) |
@@ -1031,7 +1039,7 @@ impl Type { | |||
1031 | krate: CrateId, | 1039 | krate: CrateId, |
1032 | def: impl HasResolver + Into<TyDefId> + Into<GenericDefId>, | 1040 | def: impl HasResolver + Into<TyDefId> + Into<GenericDefId>, |
1033 | ) -> Type { | 1041 | ) -> Type { |
1034 | let substs = Substs::type_params(db, def); | 1042 | let substs = Substs::build_for_def(db, def).fill_with_unknown().build(); |
1035 | let ty = db.ty(def.into()).subst(&substs); | 1043 | let ty = db.ty(def.into()).subst(&substs); |
1036 | Type::new(db, krate, def, ty) | 1044 | Type::new(db, krate, def, ty) |
1037 | } | 1045 | } |