@@ -25,7 +25,6 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>;
25
25
/// Represents module with its inner attributes.
26
26
#[ derive( Debug , Clone ) ]
27
27
pub ( crate ) struct Module < ' a > {
28
- ast_mod_kind : Option < Cow < ' a , ast:: ModKind > > ,
29
28
pub ( crate ) items : Cow < ' a , ThinVec < rustc_ast:: ptr:: P < ast:: Item > > > ,
30
29
inner_attr : ast:: AttrVec ,
31
30
pub ( crate ) span : Span ,
@@ -34,7 +33,6 @@ pub(crate) struct Module<'a> {
34
33
impl < ' a > Module < ' a > {
35
34
pub ( crate ) fn new (
36
35
mod_span : Span ,
37
- ast_mod_kind : Option < Cow < ' a , ast:: ModKind > > ,
38
36
mod_items : Cow < ' a , ThinVec < rustc_ast:: ptr:: P < ast:: Item > > > ,
39
37
mod_attrs : & [ ast:: Attribute ] ,
40
38
) -> Self {
@@ -47,7 +45,6 @@ impl<'a> Module<'a> {
47
45
items : mod_items,
48
46
inner_attr,
49
47
span : mod_span,
50
- ast_mod_kind,
51
48
}
52
49
}
53
50
@@ -139,7 +136,6 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
139
136
root_filename,
140
137
Module :: new (
141
138
mk_sp ( snippet_provider. start_pos ( ) , snippet_provider. end_pos ( ) ) ,
142
- None ,
143
139
Cow :: Borrowed ( & krate. items ) ,
144
140
& krate. attrs ,
145
141
) ,
@@ -167,17 +163,11 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
167
163
}
168
164
169
165
if let ast:: ItemKind :: Mod ( _, ref sub_mod_kind) = item. kind {
170
- let span = item. span ;
171
- self . visit_sub_mod (
172
- & item,
173
- Module :: new (
174
- span,
175
- Some ( Cow :: Owned ( sub_mod_kind. clone ( ) ) ) ,
176
- Cow :: Owned ( ThinVec :: new ( ) ) ,
177
- & [ ] ,
178
- ) ,
179
- false ,
180
- ) ?;
166
+ let items = match sub_mod_kind {
167
+ ast:: ModKind :: Loaded ( items, ..) => Cow :: Owned ( items. clone ( ) ) ,
168
+ _ => Cow :: Owned ( ThinVec :: new ( ) ) ,
169
+ } ;
170
+ self . visit_sub_mod ( & item, Module :: new ( item. span , items, & [ ] ) , false ) ?;
181
171
}
182
172
}
183
173
Ok ( ( ) )
@@ -194,17 +184,11 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
194
184
}
195
185
196
186
if let ast:: ItemKind :: Mod ( _, ref sub_mod_kind) = item. kind {
197
- let span = item. span ;
198
- self . visit_sub_mod (
199
- item,
200
- Module :: new (
201
- span,
202
- Some ( Cow :: Borrowed ( sub_mod_kind) ) ,
203
- Cow :: Owned ( ThinVec :: new ( ) ) ,
204
- & [ ] ,
205
- ) ,
206
- true ,
207
- ) ?;
187
+ let items = match sub_mod_kind {
188
+ ast:: ModKind :: Loaded ( items, ..) => Cow :: Borrowed ( items) ,
189
+ _ => Cow :: Owned ( ThinVec :: new ( ) ) ,
190
+ } ;
191
+ self . visit_sub_mod ( item, Module :: new ( item. span , items, & [ ] ) , true ) ?;
208
192
}
209
193
}
210
194
Ok ( ( ) )
@@ -309,15 +293,11 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
309
293
self . directory = directory;
310
294
}
311
295
if from_ast {
312
- if let Some ( Cow :: Borrowed ( ast :: ModKind :: Loaded ( items, _ , _ ) ) ) = & sub_mod. ast_mod_kind {
296
+ if let Cow :: Borrowed ( items) = sub_mod. items {
313
297
self . visit_mod_from_ast ( items) ?;
314
298
}
315
299
} else {
316
- if let Some ( Cow :: Owned ( ast:: ModKind :: Loaded ( items, _, _) ) ) = & sub_mod. ast_mod_kind {
317
- self . visit_mod_outside_ast ( items) ?;
318
- } else if let Cow :: Owned ( items) = & sub_mod. items {
319
- self . visit_mod_outside_ast ( items) ?;
320
- }
300
+ self . visit_mod_outside_ast ( & sub_mod. items ) ?;
321
301
}
322
302
Ok ( ( ) )
323
303
}
@@ -342,12 +322,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
342
322
Ok ( ( attrs, items, span) ) => Ok ( Some ( SubModKind :: External (
343
323
path,
344
324
DirectoryOwnership :: Owned { relative : None } ,
345
- Module :: new (
346
- span,
347
- Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
348
- Cow :: Owned ( items) ,
349
- & attrs,
350
- ) ,
325
+ Module :: new ( span, Cow :: Owned ( items) , & attrs) ,
351
326
) ) ) ,
352
327
Err ( ParserError :: ParseError ) => Err ( ModuleResolutionError {
353
328
module : mod_name. to_string ( ) ,
@@ -392,24 +367,14 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
392
367
Ok ( Some ( SubModKind :: External (
393
368
file_path,
394
369
dir_ownership,
395
- Module :: new (
396
- span,
397
- Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
398
- Cow :: Owned ( items) ,
399
- & attrs,
400
- ) ,
370
+ Module :: new ( span, Cow :: Owned ( items) , & attrs) ,
401
371
) ) )
402
372
}
403
373
Ok ( ( attrs, items, span) ) => {
404
374
mods_outside_ast. push ( (
405
375
file_path. clone ( ) ,
406
376
dir_ownership,
407
- Module :: new (
408
- span,
409
- Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
410
- Cow :: Owned ( items) ,
411
- & attrs,
412
- ) ,
377
+ Module :: new ( span, Cow :: Owned ( items) , & attrs) ,
413
378
) ) ;
414
379
if should_insert {
415
380
mods_outside_ast. push ( ( file_path, dir_ownership, sub_mod. clone ( ) ) ) ;
@@ -532,12 +497,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
532
497
result. push ( (
533
498
actual_path,
534
499
DirectoryOwnership :: Owned { relative : None } ,
535
- Module :: new (
536
- span,
537
- Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
538
- Cow :: Owned ( items) ,
539
- & attrs,
540
- ) ,
500
+ Module :: new ( span, Cow :: Owned ( items) , & attrs) ,
541
501
) )
542
502
}
543
503
result
0 commit comments