@@ -33,6 +33,7 @@ pub(super) struct Ctx<'a> {
3333 source_ast_id_map : Arc < AstIdMap > ,
3434 span_map : OnceCell < SpanMap > ,
3535 file : HirFileId ,
36+ top_level : Vec < ModItemId > ,
3637 visibilities : FxIndexSet < RawVisibility > ,
3738}
3839
@@ -45,6 +46,7 @@ impl<'a> Ctx<'a> {
4546 file,
4647 span_map : OnceCell :: new ( ) ,
4748 visibilities : FxIndexSet :: default ( ) ,
49+ top_level : Vec :: new ( ) ,
4850 }
4951 }
5052
@@ -53,14 +55,14 @@ impl<'a> Ctx<'a> {
5355 }
5456
5557 pub ( super ) fn lower_module_items ( mut self , item_owner : & dyn HasModuleItem ) -> ItemTree {
56- self . tree . top_level =
57- item_owner. items ( ) . flat_map ( |item| self . lower_mod_item ( & item) ) . collect ( ) ;
58+ self . top_level = item_owner. items ( ) . flat_map ( |item| self . lower_mod_item ( & item) ) . collect ( ) ;
5859 self . tree . vis . arena = self . visibilities . into_iter ( ) . collect ( ) ;
60+ self . tree . top_level = self . top_level . into_boxed_slice ( ) ;
5961 self . tree
6062 }
6163
6264 pub ( super ) fn lower_macro_stmts ( mut self , stmts : ast:: MacroStmts ) -> ItemTree {
63- self . tree . top_level = stmts
65+ self . top_level = stmts
6466 . statements ( )
6567 . filter_map ( |stmt| {
6668 match stmt {
@@ -84,18 +86,19 @@ impl<'a> Ctx<'a> {
8486 if let Some ( call) = tail_macro. macro_call ( ) {
8587 cov_mark:: hit!( macro_stmt_with_trailing_macro_expr) ;
8688 if let Some ( mod_item) = self . lower_mod_item ( & call. into ( ) ) {
87- self . tree . top_level . push ( mod_item) ;
89+ self . top_level . push ( mod_item) ;
8890 }
8991 }
9092 }
9193
9294 self . tree . vis . arena = self . visibilities . into_iter ( ) . collect ( ) ;
95+ self . tree . top_level = self . top_level . into_boxed_slice ( ) ;
9396 self . tree
9497 }
9598
9699 pub ( super ) fn lower_block ( mut self , block : & ast:: BlockExpr ) -> ItemTree {
97100 self . tree . attrs . insert ( AttrOwner :: TopLevel , RawAttrs :: new ( self . db , block, self . span_map ( ) ) ) ;
98- self . tree . top_level = block
101+ self . top_level = block
99102 . statements ( )
100103 . filter_map ( |stmt| match stmt {
101104 ast:: Stmt :: Item ( item) => self . lower_mod_item ( & item) ,
@@ -111,11 +114,12 @@ impl<'a> Ctx<'a> {
111114 if let Some ( ast:: Expr :: MacroExpr ( expr) ) = block. tail_expr ( ) {
112115 if let Some ( call) = expr. macro_call ( ) {
113116 if let Some ( mod_item) = self . lower_mod_item ( & call. into ( ) ) {
114- self . tree . top_level . push ( mod_item) ;
117+ self . top_level . push ( mod_item) ;
115118 }
116119 }
117120 }
118121 self . tree . vis . arena = self . visibilities . into_iter ( ) . collect ( ) ;
122+ self . tree . top_level = self . top_level . into_boxed_slice ( ) ;
119123 self . tree
120124 }
121125
0 commit comments