@@ -29,7 +29,9 @@ use triomphe::Arc;
2929
3030use crate :: {
3131 attr:: Attrs ,
32- body:: { Body , BodyDiagnostic , BodySourceMap , ExprPtr , HygieneId , LabelPtr , PatPtr } ,
32+ body:: {
33+ Body , BodyCollector , BodyDiagnostic , BodySourceMap , ExprPtr , HygieneId , LabelPtr , PatPtr ,
34+ } ,
3335 builtin_type:: BuiltinUint ,
3436 data:: adt:: StructKind ,
3537 db:: DefDatabase ,
@@ -82,7 +84,7 @@ pub(super) fn lower(
8284 def_map : expander. module . def_map ( db) ,
8385 source_map : BodySourceMap :: default ( ) ,
8486 ast_id_map : db. ast_id_map ( expander. current_file_id ( ) ) ,
85- body : Body :: default ( ) ,
87+ body : BodyCollector :: default ( ) ,
8688 expander,
8789 current_try_block_label : None ,
8890 is_lowering_coroutine : false ,
@@ -102,7 +104,7 @@ struct ExprCollector<'a> {
102104 def_map : Arc < DefMap > ,
103105 ast_id_map : Arc < AstIdMap > ,
104106 krate : CrateId ,
105- body : Body ,
107+ body : BodyCollector ,
106108 source_map : BodySourceMap ,
107109
108110 is_lowering_coroutine : bool ,
@@ -214,6 +216,9 @@ impl ExprCollector<'_> {
214216 body : Option < ast:: Expr > ,
215217 is_async_fn : bool ,
216218 ) -> ( Body , BodySourceMap ) {
219+ let mut self_param = None ;
220+ let mut params = vec ! [ ] ;
221+
217222 let skip_body = match self . owner {
218223 DefWithBodyId :: FunctionId ( it) => self . db . attrs ( it. into ( ) ) ,
219224 DefWithBodyId :: StaticId ( it) => self . db . attrs ( it. into ( ) ) ,
@@ -226,29 +231,32 @@ impl ExprCollector<'_> {
226231 // If #[rust_analyzer::skip] annotated, only construct enough information for the signature
227232 // and skip the body.
228233 if skip_body {
229- self . body . body_expr = self . missing_expr ( ) ;
230234 if let Some ( ( param_list, mut attr_enabled) ) = param_list {
231- if let Some ( self_param ) =
235+ if let Some ( self_param_syn ) =
232236 param_list. self_param ( ) . filter ( |_| attr_enabled. next ( ) . unwrap_or ( false ) )
233237 {
234- let is_mutable =
235- self_param . mut_token ( ) . is_some ( ) && self_param . amp_token ( ) . is_none ( ) ;
238+ let is_mutable = self_param_syn . mut_token ( ) . is_some ( )
239+ && self_param_syn . amp_token ( ) . is_none ( ) ;
236240 let binding_id: la_arena:: Idx < Binding > = self . alloc_binding (
237241 Name :: new_symbol_root ( sym:: self_. clone ( ) ) ,
238242 BindingAnnotation :: new ( is_mutable, false ) ,
239243 ) ;
240- self . body . self_param = Some ( binding_id) ;
244+ self_param = Some ( binding_id) ;
241245 self . source_map . self_param =
242- Some ( self . expander . in_file ( AstPtr :: new ( & self_param ) ) ) ;
246+ Some ( self . expander . in_file ( AstPtr :: new ( & self_param_syn ) ) ) ;
243247 }
244- self . body . params = param_list
248+ params = param_list
245249 . params ( )
246250 . zip ( attr_enabled)
247251 . filter ( |( _, enabled) | * enabled)
248252 . map ( |_| self . missing_pat ( ) )
249253 . collect ( ) ;
250254 } ;
251- return ( self . body , self . source_map ) ;
255+ let body_expr = self . missing_expr ( ) ;
256+ return (
257+ self . body . finish ( body_expr, self_param, params. into_boxed_slice ( ) ) ,
258+ self . source_map ,
259+ ) ;
252260 }
253261
254262 self . awaitable_context . replace ( if is_async_fn {
@@ -264,35 +272,34 @@ impl ExprCollector<'_> {
264272 }
265273 } ) ;
266274 if let Some ( ( param_list, mut attr_enabled) ) = param_list {
267- let mut params = vec ! [ ] ;
268- if let Some ( self_param) =
275+ if let Some ( self_param_syn) =
269276 param_list. self_param ( ) . filter ( |_| attr_enabled. next ( ) . unwrap_or ( false ) )
270277 {
271278 let is_mutable =
272- self_param . mut_token ( ) . is_some ( ) && self_param . amp_token ( ) . is_none ( ) ;
279+ self_param_syn . mut_token ( ) . is_some ( ) && self_param_syn . amp_token ( ) . is_none ( ) ;
273280 let binding_id: la_arena:: Idx < Binding > = self . alloc_binding (
274281 Name :: new_symbol_root ( sym:: self_. clone ( ) ) ,
275282 BindingAnnotation :: new ( is_mutable, false ) ,
276283 ) ;
277- let hygiene = self_param
284+ let hygiene = self_param_syn
278285 . name ( )
279286 . map ( |name| self . hygiene_id_for ( name. syntax ( ) . text_range ( ) . start ( ) ) )
280287 . unwrap_or ( HygieneId :: ROOT ) ;
281288 if !hygiene. is_root ( ) {
282289 self . body . binding_hygiene . insert ( binding_id, hygiene) ;
283290 }
284- self . body . self_param = Some ( binding_id) ;
285- self . source_map . self_param = Some ( self . expander . in_file ( AstPtr :: new ( & self_param) ) ) ;
291+ self_param = Some ( binding_id) ;
292+ self . source_map . self_param =
293+ Some ( self . expander . in_file ( AstPtr :: new ( & self_param_syn) ) ) ;
286294 }
287295
288296 for ( param, _) in param_list. params ( ) . zip ( attr_enabled) . filter ( |( _, enabled) | * enabled)
289297 {
290298 let param_pat = self . collect_pat_top ( param. pat ( ) ) ;
291299 params. push ( param_pat) ;
292300 }
293- self . body . params = params. into_boxed_slice ( ) ;
294301 } ;
295- self . body . body_expr = self . with_label_rib ( RibKind :: Closure , |this| {
302+ let body_expr = self . with_label_rib ( RibKind :: Closure , |this| {
296303 if is_async_fn {
297304 match body {
298305 Some ( e) => {
@@ -310,7 +317,7 @@ impl ExprCollector<'_> {
310317 }
311318 } ) ;
312319
313- ( self . body , self . source_map )
320+ ( self . body . finish ( body_expr , self_param , params . into_boxed_slice ( ) ) , self . source_map )
314321 }
315322
316323 fn ctx ( & mut self ) -> LowerCtx < ' _ > {
@@ -1934,7 +1941,7 @@ impl ExprCollector<'_> {
19341941 f : impl FnOnce ( & mut Self ) -> T ,
19351942 ) -> T {
19361943 self . label_ribs . push ( LabelRib :: new ( RibKind :: Normal (
1937- self . body [ label] . name . clone ( ) ,
1944+ self . body . labels [ label] . name . clone ( ) ,
19381945 label,
19391946 hygiene,
19401947 ) ) ) ;
0 commit comments