3
3
use std:: { collections:: hash_map:: Entry , mem, sync:: Arc } ;
4
4
5
5
use hir_expand:: { ast_id_map:: AstIdMap , hygiene:: Hygiene , name:: known, HirFileId } ;
6
- use smallvec:: SmallVec ;
7
6
use syntax:: {
8
7
ast:: { self , ModuleItemOwner } ,
9
8
SyntaxNode , WalkEvent ,
@@ -20,17 +19,6 @@ fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
20
19
FileItemTreeId { index, _p : PhantomData }
21
20
}
22
21
23
- struct ModItems ( SmallVec < [ ModItem ; 1 ] > ) ;
24
-
25
- impl < T > From < T > for ModItems
26
- where
27
- T : Into < ModItem > ,
28
- {
29
- fn from ( t : T ) -> Self {
30
- ModItems ( SmallVec :: from_buf ( [ t. into ( ) ; 1 ] ) )
31
- }
32
- }
33
-
34
22
pub ( super ) struct Ctx < ' a > {
35
23
db : & ' a dyn DefDatabase ,
36
24
tree : ItemTree ,
@@ -53,11 +41,8 @@ impl<'a> Ctx<'a> {
53
41
}
54
42
55
43
pub ( super ) fn lower_module_items ( mut self , item_owner : & dyn ModuleItemOwner ) -> ItemTree {
56
- self . tree . top_level = item_owner
57
- . items ( )
58
- . flat_map ( |item| self . lower_mod_item ( & item, false ) )
59
- . flat_map ( |items| items. 0 )
60
- . collect ( ) ;
44
+ self . tree . top_level =
45
+ item_owner. items ( ) . flat_map ( |item| self . lower_mod_item ( & item, false ) ) . collect ( ) ;
61
46
self . tree
62
47
}
63
48
@@ -69,7 +54,6 @@ impl<'a> Ctx<'a> {
69
54
_ => None ,
70
55
} )
71
56
. flat_map ( |item| self . lower_mod_item ( & item, false ) )
72
- . flat_map ( |items| items. 0 )
73
57
. collect ( ) ;
74
58
75
59
// Non-items need to have their inner items collected.
@@ -96,7 +80,7 @@ impl<'a> Ctx<'a> {
96
80
self . tree . data_mut ( )
97
81
}
98
82
99
- fn lower_mod_item ( & mut self , item : & ast:: Item , inner : bool ) -> Option < ModItems > {
83
+ fn lower_mod_item ( & mut self , item : & ast:: Item , inner : bool ) -> Option < ModItem > {
100
84
// Collect inner items for 1-to-1-lowered items.
101
85
match item {
102
86
ast:: Item :: Struct ( _)
@@ -127,34 +111,28 @@ impl<'a> Ctx<'a> {
127
111
} ;
128
112
129
113
let attrs = RawAttrs :: new ( self . db , item, & self . hygiene ) ;
130
- let items = match item {
131
- ast:: Item :: Struct ( ast) => self . lower_struct ( ast) . map ( Into :: into) ,
132
- ast:: Item :: Union ( ast) => self . lower_union ( ast) . map ( Into :: into) ,
133
- ast:: Item :: Enum ( ast) => self . lower_enum ( ast) . map ( Into :: into) ,
134
- ast:: Item :: Fn ( ast) => self . lower_function ( ast) . map ( Into :: into) ,
135
- ast:: Item :: TypeAlias ( ast) => self . lower_type_alias ( ast) . map ( Into :: into) ,
136
- ast:: Item :: Static ( ast) => self . lower_static ( ast) . map ( Into :: into) ,
137
- ast:: Item :: Const ( ast) => Some ( self . lower_const ( ast) . into ( ) ) ,
138
- ast:: Item :: Module ( ast) => self . lower_module ( ast) . map ( Into :: into) ,
139
- ast:: Item :: Trait ( ast) => self . lower_trait ( ast) . map ( Into :: into) ,
140
- ast:: Item :: Impl ( ast) => self . lower_impl ( ast) . map ( Into :: into) ,
141
- ast:: Item :: Use ( ast) => Some ( ModItems (
142
- self . lower_use ( ast) . into_iter ( ) . map ( Into :: into) . collect :: < SmallVec < _ > > ( ) ,
143
- ) ) ,
144
- ast:: Item :: ExternCrate ( ast) => self . lower_extern_crate ( ast) . map ( Into :: into) ,
145
- ast:: Item :: MacroCall ( ast) => self . lower_macro_call ( ast) . map ( Into :: into) ,
146
- ast:: Item :: MacroRules ( ast) => self . lower_macro_rules ( ast) . map ( Into :: into) ,
147
- ast:: Item :: MacroDef ( ast) => self . lower_macro_def ( ast) . map ( Into :: into) ,
148
- ast:: Item :: ExternBlock ( ast) => Some ( self . lower_extern_block ( ast) . into ( ) ) ,
114
+ let item: ModItem = match item {
115
+ ast:: Item :: Struct ( ast) => self . lower_struct ( ast) ?. into ( ) ,
116
+ ast:: Item :: Union ( ast) => self . lower_union ( ast) ?. into ( ) ,
117
+ ast:: Item :: Enum ( ast) => self . lower_enum ( ast) ?. into ( ) ,
118
+ ast:: Item :: Fn ( ast) => self . lower_function ( ast) ?. into ( ) ,
119
+ ast:: Item :: TypeAlias ( ast) => self . lower_type_alias ( ast) ?. into ( ) ,
120
+ ast:: Item :: Static ( ast) => self . lower_static ( ast) ?. into ( ) ,
121
+ ast:: Item :: Const ( ast) => self . lower_const ( ast) . into ( ) ,
122
+ ast:: Item :: Module ( ast) => self . lower_module ( ast) ?. into ( ) ,
123
+ ast:: Item :: Trait ( ast) => self . lower_trait ( ast) ?. into ( ) ,
124
+ ast:: Item :: Impl ( ast) => self . lower_impl ( ast) ?. into ( ) ,
125
+ ast:: Item :: Use ( ast) => self . lower_use ( ast) ?. into ( ) ,
126
+ ast:: Item :: ExternCrate ( ast) => self . lower_extern_crate ( ast) ?. into ( ) ,
127
+ ast:: Item :: MacroCall ( ast) => self . lower_macro_call ( ast) ?. into ( ) ,
128
+ ast:: Item :: MacroRules ( ast) => self . lower_macro_rules ( ast) ?. into ( ) ,
129
+ ast:: Item :: MacroDef ( ast) => self . lower_macro_def ( ast) ?. into ( ) ,
130
+ ast:: Item :: ExternBlock ( ast) => self . lower_extern_block ( ast) . into ( ) ,
149
131
} ;
150
132
151
- if !attrs. is_empty ( ) {
152
- for item in items. iter ( ) . flat_map ( |items| & items. 0 ) {
153
- self . add_attrs ( ( * item) . into ( ) , attrs. clone ( ) ) ;
154
- }
155
- }
133
+ self . add_attrs ( item. into ( ) , attrs. clone ( ) ) ;
156
134
157
- items
135
+ Some ( item )
158
136
}
159
137
160
138
fn add_attrs ( & mut self , item : AttrOwner , attrs : RawAttrs ) {
@@ -188,12 +166,10 @@ impl<'a> Ctx<'a> {
188
166
} ,
189
167
ast:: Item ( item) => {
190
168
// FIXME: This triggers for macro calls in expression/pattern/type position
191
- let mod_items = self . lower_mod_item( & item, true ) ;
169
+ let mod_item = self . lower_mod_item( & item, true ) ;
192
170
let current_block = block_stack. last( ) ;
193
- if let ( Some ( mod_items) , Some ( block) ) = ( mod_items, current_block) {
194
- if !mod_items. 0 . is_empty( ) {
195
- self . data( ) . inner_items. entry( * block) . or_default( ) . extend( mod_items. 0 . iter( ) . copied( ) ) ;
196
- }
171
+ if let ( Some ( mod_item) , Some ( block) ) = ( mod_item, current_block) {
172
+ self . data( ) . inner_items. entry( * block) . or_default( ) . push( mod_item) ;
197
173
}
198
174
} ,
199
175
_ => { }
@@ -478,10 +454,7 @@ impl<'a> Ctx<'a> {
478
454
items : module
479
455
. item_list ( )
480
456
. map ( |list| {
481
- list. items ( )
482
- . flat_map ( |item| self . lower_mod_item ( & item, false ) )
483
- . flat_map ( |items| items. 0 )
484
- . collect ( )
457
+ list. items ( ) . flat_map ( |item| self . lower_mod_item ( & item, false ) ) . collect ( )
485
458
} )
486
459
. unwrap_or_else ( || {
487
460
cov_mark:: hit!( name_res_works_for_broken_modules) ;
0 commit comments