diff options
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/code_model.rs | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 849c8f6d0..a2a166e0a 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -709,11 +709,23 @@ impl Function { | |||
709 | } | 709 | } |
710 | 710 | ||
711 | pub fn params(self, db: &dyn HirDatabase) -> Vec<Param> { | 711 | pub fn params(self, db: &dyn HirDatabase) -> Vec<Param> { |
712 | let resolver = self.id.resolver(db.upcast()); | ||
713 | let ctx = hir_ty::TyLoweringContext::new(db, &resolver); | ||
714 | let environment = TraitEnvironment::lower(db, &resolver); | ||
712 | db.function_data(self.id) | 715 | db.function_data(self.id) |
713 | .params | 716 | .params |
714 | .iter() | 717 | .iter() |
715 | .skip(if self.self_param(db).is_some() { 1 } else { 0 }) | 718 | .skip(if self.self_param(db).is_some() { 1 } else { 0 }) |
716 | .map(|_| Param { _ty: () }) | 719 | .map(|type_ref| { |
720 | let ty = Type { | ||
721 | krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, | ||
722 | ty: InEnvironment { | ||
723 | value: Ty::from_hir_ext(&ctx, type_ref).0, | ||
724 | environment: environment.clone(), | ||
725 | }, | ||
726 | }; | ||
727 | Param { ty } | ||
728 | }) | ||
717 | .collect() | 729 | .collect() |
718 | } | 730 | } |
719 | 731 | ||
@@ -742,15 +754,21 @@ impl From<Mutability> for Access { | |||
742 | } | 754 | } |
743 | } | 755 | } |
744 | 756 | ||
757 | pub struct Param { | ||
758 | ty: Type, | ||
759 | } | ||
760 | |||
761 | impl Param { | ||
762 | pub fn ty(&self) -> &Type { | ||
763 | &self.ty | ||
764 | } | ||
765 | } | ||
766 | |||
745 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 767 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
746 | pub struct SelfParam { | 768 | pub struct SelfParam { |
747 | func: FunctionId, | 769 | func: FunctionId, |
748 | } | 770 | } |
749 | 771 | ||
750 | pub struct Param { | ||
751 | _ty: (), | ||
752 | } | ||
753 | |||
754 | impl SelfParam { | 772 | impl SelfParam { |
755 | pub fn access(self, db: &dyn HirDatabase) -> Access { | 773 | pub fn access(self, db: &dyn HirDatabase) -> Access { |
756 | let func_data = db.function_data(self.func); | 774 | let func_data = db.function_data(self.func); |
@@ -1276,6 +1294,14 @@ impl Type { | |||
1276 | ) | 1294 | ) |
1277 | } | 1295 | } |
1278 | 1296 | ||
1297 | pub fn remove_ref(&self) -> Option<Type> { | ||
1298 | if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Ref(_), .. }) = self.ty.value { | ||
1299 | self.ty.value.substs().map(|substs| self.derived(substs[0].clone())) | ||
1300 | } else { | ||
1301 | None | ||
1302 | } | ||
1303 | } | ||
1304 | |||
1279 | pub fn is_unknown(&self) -> bool { | 1305 | pub fn is_unknown(&self) -> bool { |
1280 | matches!(self.ty.value, Ty::Unknown) | 1306 | matches!(self.ty.value, Ty::Unknown) |
1281 | } | 1307 | } |