Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/body/lower.rs')
-rw-r--r--crates/hir-def/src/body/lower.rs49
1 files changed, 28 insertions, 21 deletions
diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs
index 583c6ac5e8..2b25dbdd7f 100644
--- a/crates/hir-def/src/body/lower.rs
+++ b/crates/hir-def/src/body/lower.rs
@@ -29,7 +29,9 @@ use triomphe::Arc;
use crate::{
attr::Attrs,
- body::{Body, BodyDiagnostic, BodySourceMap, ExprPtr, HygieneId, LabelPtr, PatPtr},
+ body::{
+ Body, BodyCollector, BodyDiagnostic, BodySourceMap, ExprPtr, HygieneId, LabelPtr, PatPtr,
+ },
builtin_type::BuiltinUint,
data::adt::StructKind,
db::DefDatabase,
@@ -82,7 +84,7 @@ pub(super) fn lower(
def_map: expander.module.def_map(db),
source_map: BodySourceMap::default(),
ast_id_map: db.ast_id_map(expander.current_file_id()),
- body: Body::default(),
+ body: BodyCollector::default(),
expander,
current_try_block_label: None,
is_lowering_coroutine: false,
@@ -102,7 +104,7 @@ struct ExprCollector<'a> {
def_map: Arc<DefMap>,
ast_id_map: Arc<AstIdMap>,
krate: CrateId,
- body: Body,
+ body: BodyCollector,
source_map: BodySourceMap,
is_lowering_coroutine: bool,
@@ -214,6 +216,9 @@ impl ExprCollector<'_> {
body: Option<ast::Expr>,
is_async_fn: bool,
) -> (Body, BodySourceMap) {
+ let mut self_param = None;
+ let mut params = vec![];
+
let skip_body = match self.owner {
DefWithBodyId::FunctionId(it) => self.db.attrs(it.into()),
DefWithBodyId::StaticId(it) => self.db.attrs(it.into()),
@@ -226,29 +231,32 @@ impl ExprCollector<'_> {
// If #[rust_analyzer::skip] annotated, only construct enough information for the signature
// and skip the body.
if skip_body {
- self.body.body_expr = self.missing_expr();
if let Some((param_list, mut attr_enabled)) = param_list {
- if let Some(self_param) =
+ if let Some(self_param_syn) =
param_list.self_param().filter(|_| attr_enabled.next().unwrap_or(false))
{
- let is_mutable =
- self_param.mut_token().is_some() && self_param.amp_token().is_none();
+ let is_mutable = self_param_syn.mut_token().is_some()
+ && self_param_syn.amp_token().is_none();
let binding_id: la_arena::Idx<Binding> = self.alloc_binding(
Name::new_symbol_root(sym::self_.clone()),
BindingAnnotation::new(is_mutable, false),
);
- self.body.self_param = Some(binding_id);
+ self_param = Some(binding_id);
self.source_map.self_param =
- Some(self.expander.in_file(AstPtr::new(&self_param)));
+ Some(self.expander.in_file(AstPtr::new(&self_param_syn)));
}
- self.body.params = param_list
+ params = param_list
.params()
.zip(attr_enabled)
.filter(|(_, enabled)| *enabled)
.map(|_| self.missing_pat())
.collect();
};
- return (self.body, self.source_map);
+ let body_expr = self.missing_expr();
+ return (
+ self.body.finish(body_expr, self_param, params.into_boxed_slice()),
+ self.source_map,
+ );
}
self.awaitable_context.replace(if is_async_fn {
@@ -264,25 +272,25 @@ impl ExprCollector<'_> {
}
});
if let Some((param_list, mut attr_enabled)) = param_list {
- let mut params = vec![];
- if let Some(self_param) =
+ if let Some(self_param_syn) =
param_list.self_param().filter(|_| attr_enabled.next().unwrap_or(false))
{
let is_mutable =
- self_param.mut_token().is_some() && self_param.amp_token().is_none();
+ self_param_syn.mut_token().is_some() && self_param_syn.amp_token().is_none();
let binding_id: la_arena::Idx<Binding> = self.alloc_binding(
Name::new_symbol_root(sym::self_.clone()),
BindingAnnotation::new(is_mutable, false),
);
- let hygiene = self_param
+ let hygiene = self_param_syn
.name()
.map(|name| self.hygiene_id_for(name.syntax().text_range().start()))
.unwrap_or(HygieneId::ROOT);
if !hygiene.is_root() {
self.body.binding_hygiene.insert(binding_id, hygiene);
}
- self.body.self_param = Some(binding_id);
- self.source_map.self_param = Some(self.expander.in_file(AstPtr::new(&self_param)));
+ self_param = Some(binding_id);
+ self.source_map.self_param =
+ Some(self.expander.in_file(AstPtr::new(&self_param_syn)));
}
for (param, _) in param_list.params().zip(attr_enabled).filter(|(_, enabled)| *enabled)
@@ -290,9 +298,8 @@ impl ExprCollector<'_> {
let param_pat = self.collect_pat_top(param.pat());
params.push(param_pat);
}
- self.body.params = params.into_boxed_slice();
};
- self.body.body_expr = self.with_label_rib(RibKind::Closure, |this| {
+ let body_expr = self.with_label_rib(RibKind::Closure, |this| {
if is_async_fn {
match body {
Some(e) => {
@@ -310,7 +317,7 @@ impl ExprCollector<'_> {
}
});
- (self.body, self.source_map)
+ (self.body.finish(body_expr, self_param, params.into_boxed_slice()), self.source_map)
}
fn ctx(&mut self) -> LowerCtx<'_> {
@@ -1934,7 +1941,7 @@ impl ExprCollector<'_> {
f: impl FnOnce(&mut Self) -> T,
) -> T {
self.label_ribs.push(LabelRib::new(RibKind::Normal(
- self.body[label].name.clone(),
+ self.body.labels[label].name.clone(),
label,
hygiene,
)));