diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-23 16:54:35 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-23 16:54:35 +0000 |
commit | 789f7aca2e768b55437c00d94b76d51f30bc7b17 (patch) | |
tree | ce6741e22f6684334d1f63ec37076d23a092fdfc /crates/hir/src | |
parent | c220b340958c447b72330148e44f24c9204f84c2 (diff) | |
parent | 6bdf505d7cb5c248093c2ba174d3ac9609515804 (diff) |
Merge #8173
8173: simplify r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/lib.rs | 15 |
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 | ||
978 | impl HasVisibility for Function { | 986 | impl 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); |