aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-23 15:50:36 +0000
committerLukas Wirth <[email protected]>2021-03-23 15:54:21 +0000
commit638dcac092c130aa817d3ca94d3ed743a6d42938 (patch)
tree18c813e15a53f96d8a10527ca0c3263b50307879 /crates/hir/src
parent0469280c8affdc6bdb96ad5bf02073725c5cfd06 (diff)
Make more use of the HIR in rename::rename_to_self
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/lib.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 5da6a0340..bdc1ad852 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -852,6 +852,7 @@ impl Function {
852 }) 852 })
853 .collect() 853 .collect()
854 } 854 }
855
855 pub fn method_params(self, db: &dyn HirDatabase) -> Option<Vec<Param>> { 856 pub fn method_params(self, db: &dyn HirDatabase) -> Option<Vec<Param>> {
856 if self.self_param(db).is_none() { 857 if self.self_param(db).is_none() {
857 return None; 858 return None;
@@ -909,7 +910,7 @@ impl From<hir_ty::Mutability> for Access {
909 } 910 }
910} 911}
911 912
912#[derive(Debug)] 913#[derive(Clone, Debug)]
913pub struct Param { 914pub struct Param {
914 func: Function, 915 func: Function,
915 /// The index in parameter list, including self parameter. 916 /// The index in parameter list, including self parameter.
@@ -922,13 +923,25 @@ impl Param {
922 &self.ty 923 &self.ty
923 } 924 }
924 925
926 pub fn as_local(&self, db: &dyn HirDatabase) -> Local {
927 let parent = DefWithBodyId::FunctionId(self.func.into());
928 let body = db.body(parent);
929 Local { parent, pat_id: body.params[self.idx] }
930 }
931
925 pub fn pattern_source(&self, db: &dyn HirDatabase) -> Option<ast::Pat> { 932 pub fn pattern_source(&self, db: &dyn HirDatabase) -> Option<ast::Pat> {
926 let params = self.func.source(db)?.value.param_list()?; 933 self.source(db).and_then(|p| p.value.pat())
934 }
935
936 pub fn source(&self, db: &dyn HirDatabase) -> Option<InFile<ast::Param>> {
937 let InFile { file_id, value } = self.func.source(db)?;
938 let params = value.param_list()?;
927 if params.self_param().is_some() { 939 if params.self_param().is_some() {
928 params.params().nth(self.idx.checked_sub(1)?)?.pat() 940 params.params().nth(self.idx.checked_sub(1)?)
929 } else { 941 } else {
930 params.params().nth(self.idx)?.pat() 942 params.params().nth(self.idx)
931 } 943 }
944 .map(|value| InFile { file_id, value })
932 } 945 }
933} 946}
934 947