@@ -33,6 +33,7 @@ pub(super) struct Ctx<'a> {
33
33
source_ast_id_map : Arc < AstIdMap > ,
34
34
span_map : OnceCell < SpanMap > ,
35
35
file : HirFileId ,
36
+ top_level : Vec < ModItemId > ,
36
37
visibilities : FxIndexSet < RawVisibility > ,
37
38
}
38
39
@@ -45,6 +46,7 @@ impl<'a> Ctx<'a> {
45
46
file,
46
47
span_map : OnceCell :: new ( ) ,
47
48
visibilities : FxIndexSet :: default ( ) ,
49
+ top_level : Vec :: new ( ) ,
48
50
}
49
51
}
50
52
@@ -53,14 +55,14 @@ impl<'a> Ctx<'a> {
53
55
}
54
56
55
57
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 ( ) ;
58
59
self . tree . vis . arena = self . visibilities . into_iter ( ) . collect ( ) ;
60
+ self . tree . top_level = self . top_level . into_boxed_slice ( ) ;
59
61
self . tree
60
62
}
61
63
62
64
pub ( super ) fn lower_macro_stmts ( mut self , stmts : ast:: MacroStmts ) -> ItemTree {
63
- self . tree . top_level = stmts
65
+ self . top_level = stmts
64
66
. statements ( )
65
67
. filter_map ( |stmt| {
66
68
match stmt {
@@ -84,18 +86,19 @@ impl<'a> Ctx<'a> {
84
86
if let Some ( call) = tail_macro. macro_call ( ) {
85
87
cov_mark:: hit!( macro_stmt_with_trailing_macro_expr) ;
86
88
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) ;
88
90
}
89
91
}
90
92
}
91
93
92
94
self . tree . vis . arena = self . visibilities . into_iter ( ) . collect ( ) ;
95
+ self . tree . top_level = self . top_level . into_boxed_slice ( ) ;
93
96
self . tree
94
97
}
95
98
96
99
pub ( super ) fn lower_block ( mut self , block : & ast:: BlockExpr ) -> ItemTree {
97
100
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
99
102
. statements ( )
100
103
. filter_map ( |stmt| match stmt {
101
104
ast:: Stmt :: Item ( item) => self . lower_mod_item ( & item) ,
@@ -111,11 +114,12 @@ impl<'a> Ctx<'a> {
111
114
if let Some ( ast:: Expr :: MacroExpr ( expr) ) = block. tail_expr ( ) {
112
115
if let Some ( call) = expr. macro_call ( ) {
113
116
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) ;
115
118
}
116
119
}
117
120
}
118
121
self . tree . vis . arena = self . visibilities . into_iter ( ) . collect ( ) ;
122
+ self . tree . top_level = self . top_level . into_boxed_slice ( ) ;
119
123
self . tree
120
124
}
121
125
0 commit comments