@@ -271,7 +271,7 @@ impl ExprCollector<'_> {
271271 ast:: Expr :: BlockExpr ( e) => match e. modifier ( ) {
272272 Some ( ast:: BlockModifier :: Try ( _) ) => self . desugar_try_block ( e) ,
273273 Some ( ast:: BlockModifier :: Unsafe ( _) ) => {
274- self . collect_block_ ( e, |id, statements, tail| Expr :: Unsafe {
274+ self . collect_block_ ( e, |id, statements, tail, _ | Expr :: Unsafe {
275275 id,
276276 statements,
277277 tail,
@@ -280,17 +280,20 @@ impl ExprCollector<'_> {
280280 Some ( ast:: BlockModifier :: Label ( label) ) => {
281281 let label = self . collect_label ( label) ;
282282 self . with_labeled_rib ( label, |this| {
283- this. collect_block_ ( e, |id, statements, tail| Expr :: Block {
284- id,
285- statements,
286- tail,
287- label : Some ( label) ,
283+ this. collect_block_ ( e, |id, statements, tail, has_trailing_item_decl| {
284+ Expr :: Block {
285+ id,
286+ statements,
287+ tail,
288+ label : Some ( label) ,
289+ has_trailing_item_decl,
290+ }
288291 } )
289292 } )
290293 }
291294 Some ( ast:: BlockModifier :: Async ( _) ) => {
292295 self . with_label_rib ( RibKind :: Closure , |this| {
293- this. collect_block_ ( e, |id, statements, tail| Expr :: Async {
296+ this. collect_block_ ( e, |id, statements, tail, _ | Expr :: Async {
294297 id,
295298 statements,
296299 tail,
@@ -710,9 +713,15 @@ impl ExprCollector<'_> {
710713
711714 let ( btail, expr_id) = self . with_labeled_rib ( label, |this| {
712715 let mut btail = None ;
713- let block = this. collect_block_ ( e, |id, statements, tail| {
716+ let block = this. collect_block_ ( e, |id, statements, tail, _ | {
714717 btail = tail;
715- Expr :: Block { id, statements, tail, label : Some ( label) }
718+ Expr :: Block {
719+ id,
720+ statements,
721+ tail,
722+ label : Some ( label) ,
723+ has_trailing_item_decl : false ,
724+ }
716725 } ) ;
717726 ( btail, block)
718727 } ) ;
@@ -1118,18 +1127,19 @@ impl ExprCollector<'_> {
11181127 }
11191128
11201129 fn collect_block ( & mut self , block : ast:: BlockExpr ) -> ExprId {
1121- self . collect_block_ ( block, |id, statements, tail| Expr :: Block {
1130+ self . collect_block_ ( block, |id, statements, tail, has_trailing_item_decl | Expr :: Block {
11221131 id,
11231132 statements,
11241133 tail,
11251134 label : None ,
1135+ has_trailing_item_decl,
11261136 } )
11271137 }
11281138
11291139 fn collect_block_ (
11301140 & mut self ,
11311141 block : ast:: BlockExpr ,
1132- mk_block : impl FnOnce ( Option < BlockId > , Box < [ Statement ] > , Option < ExprId > ) -> Expr ,
1142+ mk_block : impl FnOnce ( Option < BlockId > , Box < [ Statement ] > , Option < ExprId > , bool ) -> Expr ,
11331143 ) -> ExprId {
11341144 let block_has_items = {
11351145 let statement_has_item = block. statements ( ) . any ( |stmt| match stmt {
@@ -1178,9 +1188,15 @@ impl ExprCollector<'_> {
11781188 None
11791189 } ) ;
11801190
1191+ let has_trailing_item_decl = block
1192+ . statements ( )
1193+ . last ( )
1194+ . map_or ( false , |last_stmt| matches ! ( last_stmt, ast:: Stmt :: Item ( _) ) ) ;
11811195 let syntax_node_ptr = AstPtr :: new ( & block. into ( ) ) ;
1182- let expr_id = self
1183- . alloc_expr ( mk_block ( block_id, statements. into_boxed_slice ( ) , tail) , syntax_node_ptr) ;
1196+ let expr_id = self . alloc_expr (
1197+ mk_block ( block_id, statements. into_boxed_slice ( ) , tail, has_trailing_item_decl) ,
1198+ syntax_node_ptr,
1199+ ) ;
11841200
11851201 self . def_map = prev_def_map;
11861202 self . expander . module = prev_local_module;
0 commit comments