aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src/lib.rs')
-rw-r--r--crates/hir/src/lib.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 0d0e757fc..476fdb132 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -822,7 +822,8 @@ impl Function {
822 db.function_data(self.id) 822 db.function_data(self.id)
823 .params 823 .params
824 .iter() 824 .iter()
825 .map(|type_ref| { 825 .enumerate()
826 .map(|(idx, type_ref)| {
826 let ty = Type { 827 let ty = Type {
827 krate, 828 krate,
828 ty: InEnvironment { 829 ty: InEnvironment {
@@ -830,7 +831,7 @@ impl Function {
830 environment: environment.clone(), 831 environment: environment.clone(),
831 }, 832 },
832 }; 833 };
833 Param { ty } 834 Param { func: self, ty, idx }
834 }) 835 })
835 .collect() 836 .collect()
836 } 837 }
@@ -893,6 +894,9 @@ impl From<hir_ty::Mutability> for Access {
893 894
894#[derive(Debug)] 895#[derive(Debug)]
895pub struct Param { 896pub struct Param {
897 func: Function,
898 /// The index in parameter list, including self parameter.
899 idx: usize,
896 ty: Type, 900 ty: Type,
897} 901}
898 902
@@ -900,6 +904,15 @@ impl Param {
900 pub fn ty(&self) -> &Type { 904 pub fn ty(&self) -> &Type {
901 &self.ty 905 &self.ty
902 } 906 }
907
908 pub fn pattern_source(&self, db: &dyn HirDatabase) -> Option<ast::Pat> {
909 let params = self.func.source(db)?.value.param_list()?;
910 if params.self_param().is_some() {
911 params.params().nth(self.idx.checked_sub(1)?)?.pat()
912 } else {
913 params.params().nth(self.idx)?.pat()
914 }
915 }
903} 916}
904 917
905#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 918#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]