aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-23 16:39:43 +0000
committerLukas Wirth <[email protected]>2021-03-23 16:49:06 +0000
commit6bdf505d7cb5c248093c2ba174d3ac9609515804 (patch)
tree373a2eaadb7d5ab5b55feabae6ec3cbb29bd4a8e /crates/hir
parent065a8e87cd015ccfe5c01ad6b603f4fdad18f768 (diff)
simplify
Diffstat (limited to 'crates/hir')
-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);