aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/lib.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index bdc1ad852..eb7865c84 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -973,6 +973,14 @@ impl SelfParam {
973 Access::Owned => "self", 973 Access::Owned => "self",
974 } 974 }
975 } 975 }
976
977 pub fn source(&self, db: &dyn HirDatabase) -> Option<InFile<ast::SelfParam>> {
978 let InFile { file_id, value } = Function::from(self.func).source(db)?;
979 value
980 .param_list()
981 .and_then(|params| params.self_param())
982 .map(|value| InFile { file_id, value })
983 }
976} 984}
977 985
978impl HasVisibility for Function { 986impl HasVisibility for Function {
@@ -1348,6 +1356,13 @@ impl Local {
1348 } 1356 }
1349 } 1357 }
1350 1358
1359 pub fn as_self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
1360 match self.parent {
1361 DefWithBodyId::FunctionId(func) if self.is_self(db) => Some(SelfParam { func }),
1362 _ => None,
1363 }
1364 }
1365
1351 // FIXME: why is this an option? It shouldn't be? 1366 // FIXME: why is this an option? It shouldn't be?
1352 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { 1367 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
1353 let body = db.body(self.parent); 1368 let body = db.body(self.parent);