Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/expr_store/body.rs')
| -rw-r--r-- | crates/hir-def/src/expr_store/body.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/hir-def/src/expr_store/body.rs b/crates/hir-def/src/expr_store/body.rs index 3c7452507e..2fb47e59c5 100644 --- a/crates/hir-def/src/expr_store/body.rs +++ b/crates/hir-def/src/expr_store/body.rs @@ -2,6 +2,7 @@ //! consts. use std::ops; +use arrayvec::ArrayVec; use hir_expand::{InFile, Lookup}; use span::Edition; use syntax::ast; @@ -28,7 +29,12 @@ pub struct Body { /// If this `Body` is for the body of a constant, this will just be /// empty. pub params: Box<[PatId]>, - pub self_param: Option<BindingId>, + /// The first element, if it exists, is the real `self` binding. + /// + /// The second element is used for `async fn` (or `gen fn` etc.). These functions + /// have to put a `let self = self` inside the returned coroutine, and the second element + /// points at it. + pub self_params: ArrayVec<BindingId, 2>, } impl ops::Deref for Body { @@ -122,6 +128,16 @@ impl Body { self.store.expr_roots().next_back().unwrap() } + pub fn self_param(&self) -> Option<BindingId> { + self.self_params.first().copied() + } + + /// `async fn` (or `gen fn` etc.), have to put a `let self = self` inside the returned coroutine. + /// This function returns it. + pub fn coroutine_self_binding(&self) -> Option<BindingId> { + self.self_params.get(1).copied() + } + pub fn pretty_print( &self, db: &dyn DefDatabase, |