@@ -39,7 +39,6 @@ use crate::{
3939 RecordFieldPat , RecordLitField , Statement ,
4040 } ,
4141 item_scope:: BuiltinShadowMode ,
42- item_tree:: ItemTree ,
4342 lang_item:: LangItem ,
4443 path:: { GenericArgs , Path } ,
4544 type_ref:: { Mutability , Rawness , TypeRef } ,
@@ -53,7 +52,11 @@ pub struct LowerCtx<'a> {
5352}
5453
5554impl < ' a > LowerCtx < ' a > {
56- pub fn new ( db : & ' a dyn DefDatabase , file_id : HirFileId ) -> Self {
55+ pub fn new ( db : & ' a dyn DefDatabase , hygiene : & Hygiene , file_id : HirFileId ) -> Self {
56+ LowerCtx { db, hygiene : hygiene. clone ( ) , ast_id_map : Some ( ( file_id, OnceCell :: new ( ) ) ) }
57+ }
58+
59+ pub fn with_file_id ( db : & ' a dyn DefDatabase , file_id : HirFileId ) -> Self {
5760 LowerCtx {
5861 db,
5962 hygiene : Hygiene :: new ( db. upcast ( ) , file_id) ,
@@ -230,7 +233,7 @@ impl ExprCollector<'_> {
230233 }
231234
232235 fn ctx ( & self ) -> LowerCtx < ' _ > {
233- LowerCtx :: new ( self . db , self . expander . current_file_id )
236+ self . expander . ctx ( self . db )
234237 }
235238
236239 fn alloc_expr ( & mut self , expr : Expr , ptr : ExprPtr ) -> ExprId {
@@ -973,8 +976,18 @@ impl ExprCollector<'_> {
973976 block : ast:: BlockExpr ,
974977 mk_block : impl FnOnce ( Option < BlockId > , Box < [ Statement ] > , Option < ExprId > ) -> Expr ,
975978 ) -> ExprId {
976- let block_id = if ItemTree :: block_has_items ( self . db , self . expander . current_file_id , & block)
977- {
979+ let block_has_items = {
980+ let statement_has_item = block. statements ( ) . any ( |stmt| match stmt {
981+ ast:: Stmt :: Item ( _) => true ,
982+ // Macro calls can be both items and expressions. The syntax library always treats
983+ // them as expressions here, so we undo that.
984+ ast:: Stmt :: ExprStmt ( es) => matches ! ( es. expr( ) , Some ( ast:: Expr :: MacroExpr ( _) ) ) ,
985+ _ => false ,
986+ } ) ;
987+ statement_has_item || matches ! ( block. tail_expr( ) , Some ( ast:: Expr :: MacroExpr ( _) ) )
988+ } ;
989+
990+ let block_id = if block_has_items {
978991 let file_local_id = self . ast_id_map . ast_id ( & block) ;
979992 let ast_id = AstId :: new ( self . expander . current_file_id , file_local_id) ;
980993 Some ( self . db . intern_block ( BlockLoc {
0 commit comments