This commit is contained in:
Lukas Wirth 2021-03-23 17:39:43 +01:00
parent 065a8e87cd
commit 6bdf505d7c
2 changed files with 56 additions and 40 deletions

View file

@ -973,6 +973,14 @@ impl SelfParam {
Access::Owned => "self",
}
}
pub fn source(&self, db: &dyn HirDatabase) -> Option<InFile<ast::SelfParam>> {
let InFile { file_id, value } = Function::from(self.func).source(db)?;
value
.param_list()
.and_then(|params| params.self_param())
.map(|value| InFile { file_id, value })
}
}
impl HasVisibility for Function {
@ -1348,6 +1356,13 @@ impl Local {
}
}
pub fn as_self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
match self.parent {
DefWithBodyId::FunctionId(func) if self.is_self(db) => Some(SelfParam { func }),
_ => None,
}
}
// FIXME: why is this an option? It shouldn't be?
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
let body = db.body(self.parent);