params: Option<ast::ParamList>,
body: Option<ast::Expr>,
) -> (Body, BodySourceMap) {
- let ctx = LowerCtx::new(db, expander.current_file_id.clone());
-
ExprCollector {
db,
def,
expander,
- ctx,
source_map: BodySourceMap::default(),
body: Body {
exprs: Arena::default(),
db: &'a dyn DefDatabase,
def: DefWithBodyId,
expander: Expander,
- ctx: LowerCtx,
body: Body,
source_map: BodySourceMap,
}
(self.body, self.source_map)
}
+ fn ctx(&self) -> LowerCtx {
+ LowerCtx::new(self.db, self.expander.current_file_id)
+ }
+
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
let src = self.expander.to_source(ptr);
let id = self.make_expr(expr, Ok(src.clone()));
};
let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
let generic_args =
- e.type_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx, it));
+ e.type_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx(), it));
self.alloc_expr(
Expr::MethodCall { receiver, method_name, args, generic_args },
syntax_ptr,
}
ast::Expr::CastExpr(e) => {
let expr = self.collect_expr_opt(e.expr());
- let type_ref = TypeRef::from_ast_opt(&self.ctx, e.type_ref());
+ let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.type_ref());
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
}
ast::Expr::RefExpr(e) => {
for param in pl.params() {
let pat = self.collect_pat_opt(param.pat());
let type_ref =
- param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx, it));
+ param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it));
args.push(pat);
arg_types.push(type_ref);
}
let ret_type = e
.ret_type()
.and_then(|r| r.type_ref())
- .map(|it| TypeRef::from_ast(&self.ctx, it));
+ .map(|it| TypeRef::from_ast(&self.ctx(), it));
let body = self.collect_expr_opt(e.body());
self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr)
}
.map(|s| match s {
ast::Stmt::LetStmt(stmt) => {
let pat = self.collect_pat_opt(stmt.pat());
- let type_ref = stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx, it));
+ let type_ref =
+ stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it));
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
Statement::Let { pat, type_ref, initializer }
}