@@ -39,7 +39,6 @@ use crate::{
39
39
RecordFieldPat , RecordLitField , Statement ,
40
40
} ,
41
41
item_scope:: BuiltinShadowMode ,
42
- item_tree:: ItemTree ,
43
42
lang_item:: LangItem ,
44
43
path:: { GenericArgs , Path } ,
45
44
type_ref:: { Mutability , Rawness , TypeRef } ,
@@ -53,7 +52,11 @@ pub struct LowerCtx<'a> {
53
52
}
54
53
55
54
impl < ' 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 {
57
60
LowerCtx {
58
61
db,
59
62
hygiene : Hygiene :: new ( db. upcast ( ) , file_id) ,
@@ -230,7 +233,7 @@ impl ExprCollector<'_> {
230
233
}
231
234
232
235
fn ctx ( & self ) -> LowerCtx < ' _ > {
233
- LowerCtx :: new ( self . db , self . expander . current_file_id )
236
+ self . expander . ctx ( self . db )
234
237
}
235
238
236
239
fn alloc_expr ( & mut self , expr : Expr , ptr : ExprPtr ) -> ExprId {
@@ -973,8 +976,18 @@ impl ExprCollector<'_> {
973
976
block : ast:: BlockExpr ,
974
977
mk_block : impl FnOnce ( Option < BlockId > , Box < [ Statement ] > , Option < ExprId > ) -> Expr ,
975
978
) -> 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 {
978
991
let file_local_id = self . ast_id_map . ast_id ( & block) ;
979
992
let ast_id = AstId :: new ( self . expander . current_file_id , file_local_id) ;
980
993
Some ( self . db . intern_block ( BlockLoc {
0 commit comments