@@ -37,7 +37,7 @@ use crate::{
37
37
item_scope:: BuiltinShadowMode ,
38
38
path:: { GenericArgs , Path } ,
39
39
type_ref:: { Mutability , Rawness , TypeRef } ,
40
- AdtId , BlockLoc , ModuleDefId , UnresolvedMacro ,
40
+ AdtId , BlockId , BlockLoc , ModuleDefId , UnresolvedMacro ,
41
41
} ;
42
42
43
43
pub struct LowerCtx < ' a > {
@@ -238,33 +238,32 @@ impl ExprCollector<'_> {
238
238
}
239
239
ast:: Expr :: BlockExpr ( e) => match e. modifier ( ) {
240
240
Some ( ast:: BlockModifier :: Try ( _) ) => {
241
- let body = self . collect_block ( e) ;
242
- self . alloc_expr ( Expr :: TryBlock { body } , syntax_ptr)
241
+ self . collect_block_ ( e, |id, statements, tail| Expr :: TryBlock {
242
+ id,
243
+ statements,
244
+ tail,
245
+ } )
243
246
}
244
247
Some ( ast:: BlockModifier :: Unsafe ( _) ) => {
245
- let body = self . collect_block ( e) ;
246
- self . alloc_expr ( Expr :: Unsafe { body } , syntax_ptr)
248
+ self . collect_block_ ( e, |id, statements, tail| Expr :: Unsafe {
249
+ id,
250
+ statements,
251
+ tail,
252
+ } )
247
253
}
248
- // FIXME: we need to record these effects somewhere...
249
254
Some ( ast:: BlockModifier :: Label ( label) ) => {
250
255
let label = self . collect_label ( label) ;
251
- let res = self . collect_block ( e) ;
252
- match & mut self . body . exprs [ res] {
253
- Expr :: Block { label : block_label, .. } => {
254
- * block_label = Some ( label) ;
255
- }
256
- _ => unreachable ! ( ) ,
257
- }
258
- res
259
- }
260
- Some ( ast:: BlockModifier :: Async ( _) ) => {
261
- let body = self . collect_block ( e) ;
262
- self . alloc_expr ( Expr :: Async { body } , syntax_ptr)
263
- }
264
- Some ( ast:: BlockModifier :: Const ( _) ) => {
265
- let body = self . collect_block ( e) ;
266
- self . alloc_expr ( Expr :: Const { body } , syntax_ptr)
256
+ self . collect_block_ ( e, |id, statements, tail| Expr :: Block {
257
+ id,
258
+ statements,
259
+ tail,
260
+ label : Some ( label) ,
261
+ } )
267
262
}
263
+ Some ( ast:: BlockModifier :: Async ( _) ) => self
264
+ . collect_block_ ( e, |id, statements, tail| Expr :: Async { id, statements, tail } ) ,
265
+ Some ( ast:: BlockModifier :: Const ( _) ) => self
266
+ . collect_block_ ( e, |id, statements, tail| Expr :: Const { id, statements, tail } ) ,
268
267
None => self . collect_block ( e) ,
269
268
} ,
270
269
ast:: Expr :: LoopExpr ( e) => {
@@ -737,6 +736,19 @@ impl ExprCollector<'_> {
737
736
}
738
737
739
738
fn collect_block ( & mut self , block : ast:: BlockExpr ) -> ExprId {
739
+ self . collect_block_ ( block, |id, statements, tail| Expr :: Block {
740
+ id,
741
+ statements,
742
+ tail,
743
+ label : None ,
744
+ } )
745
+ }
746
+
747
+ fn collect_block_ (
748
+ & mut self ,
749
+ block : ast:: BlockExpr ,
750
+ mk_block : impl FnOnce ( BlockId , Box < [ Statement ] > , Option < ExprId > ) -> Expr ,
751
+ ) -> ExprId {
740
752
let file_local_id = self . ast_id_map . ast_id ( & block) ;
741
753
let ast_id = AstId :: new ( self . expander . current_file_id , file_local_id) ;
742
754
let block_loc =
@@ -769,15 +781,8 @@ impl ExprCollector<'_> {
769
781
} ) ;
770
782
771
783
let syntax_node_ptr = AstPtr :: new ( & block. into ( ) ) ;
772
- let expr_id = self . alloc_expr (
773
- Expr :: Block {
774
- id : block_id,
775
- statements : statements. into_boxed_slice ( ) ,
776
- tail,
777
- label : None ,
778
- } ,
779
- syntax_node_ptr,
780
- ) ;
784
+ let expr_id = self
785
+ . alloc_expr ( mk_block ( block_id, statements. into_boxed_slice ( ) , tail) , syntax_node_ptr) ;
781
786
782
787
self . expander . def_map = prev_def_map;
783
788
self . expander . module = prev_local_module;
0 commit comments