@@ -60,13 +60,10 @@ pub(super) fn lower(
60
60
params : Option < ast:: ParamList > ,
61
61
body : Option < ast:: Expr > ,
62
62
) -> ( Body , BodySourceMap ) {
63
- let ctx = LowerCtx :: new ( db, expander. current_file_id . clone ( ) ) ;
64
-
65
63
ExprCollector {
66
64
db,
67
65
def,
68
66
expander,
69
- ctx,
70
67
source_map : BodySourceMap :: default ( ) ,
71
68
body : Body {
72
69
exprs : Arena :: default ( ) ,
@@ -83,7 +80,6 @@ struct ExprCollector<'a> {
83
80
db : & ' a dyn DefDatabase ,
84
81
def : DefWithBodyId ,
85
82
expander : Expander ,
86
- ctx : LowerCtx ,
87
83
body : Body ,
88
84
source_map : BodySourceMap ,
89
85
}
@@ -122,6 +118,10 @@ impl ExprCollector<'_> {
122
118
( self . body , self . source_map )
123
119
}
124
120
121
+ fn ctx ( & self ) -> LowerCtx {
122
+ LowerCtx :: new ( self . db , self . expander . current_file_id )
123
+ }
124
+
125
125
fn alloc_expr ( & mut self , expr : Expr , ptr : AstPtr < ast:: Expr > ) -> ExprId {
126
126
let src = self . expander . to_source ( ptr) ;
127
127
let id = self . make_expr ( expr, Ok ( src. clone ( ) ) ) ;
@@ -268,7 +268,7 @@ impl ExprCollector<'_> {
268
268
} ;
269
269
let method_name = e. name_ref ( ) . map ( |nr| nr. as_name ( ) ) . unwrap_or_else ( Name :: missing) ;
270
270
let generic_args =
271
- e. type_arg_list ( ) . and_then ( |it| GenericArgs :: from_ast ( & self . ctx , it) ) ;
271
+ e. type_arg_list ( ) . and_then ( |it| GenericArgs :: from_ast ( & self . ctx ( ) , it) ) ;
272
272
self . alloc_expr (
273
273
Expr :: MethodCall { receiver, method_name, args, generic_args } ,
274
274
syntax_ptr,
@@ -373,7 +373,7 @@ impl ExprCollector<'_> {
373
373
}
374
374
ast:: Expr :: CastExpr ( e) => {
375
375
let expr = self . collect_expr_opt ( e. expr ( ) ) ;
376
- let type_ref = TypeRef :: from_ast_opt ( & self . ctx , e. type_ref ( ) ) ;
376
+ let type_ref = TypeRef :: from_ast_opt ( & self . ctx ( ) , e. type_ref ( ) ) ;
377
377
self . alloc_expr ( Expr :: Cast { expr, type_ref } , syntax_ptr)
378
378
}
379
379
ast:: Expr :: RefExpr ( e) => {
@@ -396,15 +396,15 @@ impl ExprCollector<'_> {
396
396
for param in pl. params ( ) {
397
397
let pat = self . collect_pat_opt ( param. pat ( ) ) ;
398
398
let type_ref =
399
- param. ascribed_type ( ) . map ( |it| TypeRef :: from_ast ( & self . ctx , it) ) ;
399
+ param. ascribed_type ( ) . map ( |it| TypeRef :: from_ast ( & self . ctx ( ) , it) ) ;
400
400
args. push ( pat) ;
401
401
arg_types. push ( type_ref) ;
402
402
}
403
403
}
404
404
let ret_type = e
405
405
. ret_type ( )
406
406
. and_then ( |r| r. type_ref ( ) )
407
- . map ( |it| TypeRef :: from_ast ( & self . ctx , it) ) ;
407
+ . map ( |it| TypeRef :: from_ast ( & self . ctx ( ) , it) ) ;
408
408
let body = self . collect_expr_opt ( e. body ( ) ) ;
409
409
self . alloc_expr ( Expr :: Lambda { args, arg_types, ret_type, body } , syntax_ptr)
410
410
}
@@ -507,7 +507,8 @@ impl ExprCollector<'_> {
507
507
. map ( |s| match s {
508
508
ast:: Stmt :: LetStmt ( stmt) => {
509
509
let pat = self . collect_pat_opt ( stmt. pat ( ) ) ;
510
- let type_ref = stmt. ascribed_type ( ) . map ( |it| TypeRef :: from_ast ( & self . ctx , it) ) ;
510
+ let type_ref =
511
+ stmt. ascribed_type ( ) . map ( |it| TypeRef :: from_ast ( & self . ctx ( ) , it) ) ;
511
512
let initializer = stmt. initializer ( ) . map ( |e| self . collect_expr ( e) ) ;
512
513
Statement :: Let { pat, type_ref, initializer }
513
514
}
0 commit comments