diff options
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r-- | crates/hir/src/code_model.rs | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 849c8f6d0..567fd91af 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -383,6 +383,16 @@ impl Module { | |||
383 | pub fn find_use_path(self, db: &dyn DefDatabase, item: impl Into<ItemInNs>) -> Option<ModPath> { | 383 | pub fn find_use_path(self, db: &dyn DefDatabase, item: impl Into<ItemInNs>) -> Option<ModPath> { |
384 | hir_def::find_path::find_path(db, item.into(), self.into()) | 384 | hir_def::find_path::find_path(db, item.into(), self.into()) |
385 | } | 385 | } |
386 | |||
387 | /// Finds a path that can be used to refer to the given item from within | ||
388 | /// this module, if possible. This is used for returning import paths for use-statements. | ||
389 | pub fn find_use_path_prefixed( | ||
390 | self, | ||
391 | db: &dyn DefDatabase, | ||
392 | item: impl Into<ItemInNs>, | ||
393 | ) -> Option<ModPath> { | ||
394 | hir_def::find_path::find_path_prefixed(db, item.into(), self.into()) | ||
395 | } | ||
386 | } | 396 | } |
387 | 397 | ||
388 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 398 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -709,11 +719,23 @@ impl Function { | |||
709 | } | 719 | } |
710 | 720 | ||
711 | pub fn params(self, db: &dyn HirDatabase) -> Vec<Param> { | 721 | pub fn params(self, db: &dyn HirDatabase) -> Vec<Param> { |
722 | let resolver = self.id.resolver(db.upcast()); | ||
723 | let ctx = hir_ty::TyLoweringContext::new(db, &resolver); | ||
724 | let environment = TraitEnvironment::lower(db, &resolver); | ||
712 | db.function_data(self.id) | 725 | db.function_data(self.id) |
713 | .params | 726 | .params |
714 | .iter() | 727 | .iter() |
715 | .skip(if self.self_param(db).is_some() { 1 } else { 0 }) | 728 | .skip(if self.self_param(db).is_some() { 1 } else { 0 }) |
716 | .map(|_| Param { _ty: () }) | 729 | .map(|type_ref| { |
730 | let ty = Type { | ||
731 | krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, | ||
732 | ty: InEnvironment { | ||
733 | value: Ty::from_hir_ext(&ctx, type_ref).0, | ||
734 | environment: environment.clone(), | ||
735 | }, | ||
736 | }; | ||
737 | Param { ty } | ||
738 | }) | ||
717 | .collect() | 739 | .collect() |
718 | } | 740 | } |
719 | 741 | ||
@@ -742,15 +764,21 @@ impl From<Mutability> for Access { | |||
742 | } | 764 | } |
743 | } | 765 | } |
744 | 766 | ||
767 | pub struct Param { | ||
768 | ty: Type, | ||
769 | } | ||
770 | |||
771 | impl Param { | ||
772 | pub fn ty(&self) -> &Type { | ||
773 | &self.ty | ||
774 | } | ||
775 | } | ||
776 | |||
745 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 777 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
746 | pub struct SelfParam { | 778 | pub struct SelfParam { |
747 | func: FunctionId, | 779 | func: FunctionId, |
748 | } | 780 | } |
749 | 781 | ||
750 | pub struct Param { | ||
751 | _ty: (), | ||
752 | } | ||
753 | |||
754 | impl SelfParam { | 782 | impl SelfParam { |
755 | pub fn access(self, db: &dyn HirDatabase) -> Access { | 783 | pub fn access(self, db: &dyn HirDatabase) -> Access { |
756 | let func_data = db.function_data(self.func); | 784 | let func_data = db.function_data(self.func); |
@@ -1276,6 +1304,14 @@ impl Type { | |||
1276 | ) | 1304 | ) |
1277 | } | 1305 | } |
1278 | 1306 | ||
1307 | pub fn remove_ref(&self) -> Option<Type> { | ||
1308 | if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Ref(_), .. }) = self.ty.value { | ||
1309 | self.ty.value.substs().map(|substs| self.derived(substs[0].clone())) | ||
1310 | } else { | ||
1311 | None | ||
1312 | } | ||
1313 | } | ||
1314 | |||
1279 | pub fn is_unknown(&self) -> bool { | 1315 | pub fn is_unknown(&self) -> bool { |
1280 | matches!(self.ty.value, Ty::Unknown) | 1316 | matches!(self.ty.value, Ty::Unknown) |
1281 | } | 1317 | } |