@@ -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
@@ -57,10 +54,6 @@ impl<'a> Module<'a> {
57
54
58
55
pub ( crate ) fn to_owned ( & self ) -> Module < ' static > {
59
56
Module {
60
- ast_mod_kind : self
61
- . ast_mod_kind
62
- . as_ref ( )
63
- . map ( |i| Cow :: Owned ( ( * * i) . clone ( ) ) ) ,
64
57
items : Cow :: Owned ( ( & * self . items ) . clone ( ) ) ,
65
58
inner_attr : self . inner_attr . clone ( ) ,
66
59
span : self . span ,
@@ -151,7 +144,6 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
151
144
root_filename,
152
145
Module :: new (
153
146
mk_sp ( snippet_provider. start_pos ( ) , snippet_provider. end_pos ( ) ) ,
154
- None ,
155
147
Cow :: Borrowed ( & krate. items ) ,
156
148
& krate. attrs ,
157
149
) ,
@@ -175,15 +167,11 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
175
167
if is_cfg_if ( item) {
176
168
self . visit_cfg_if ( item) ?;
177
169
} else if let ast:: ItemKind :: Mod ( _, sub_mod_kind) = & item. kind {
178
- self . visit_sub_mod (
179
- & item,
180
- Module :: new (
181
- item. span ,
182
- Some ( Cow :: Borrowed ( sub_mod_kind) ) ,
183
- Cow :: Owned ( ThinVec :: new ( ) ) ,
184
- & [ ] ,
185
- ) ,
186
- ) ?;
170
+ let items = match sub_mod_kind {
171
+ ast:: ModKind :: Loaded ( items, ..) => Cow :: Borrowed ( items) ,
172
+ _ => Cow :: Owned ( ThinVec :: new ( ) ) ,
173
+ } ;
174
+ self . visit_sub_mod ( item, Module :: new ( item. span , items, & [ ] ) ) ?;
187
175
}
188
176
}
189
177
Ok ( ( ) )
@@ -284,11 +272,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
284
272
if let Some ( directory) = directory {
285
273
self . directory = directory;
286
274
}
287
- if let Some ( ast:: ModKind :: Loaded ( items, _, _) ) = sub_mod. ast_mod_kind . as_deref ( ) {
288
- self . visit_mod ( & items)
289
- } else {
290
- self . visit_mod ( & sub_mod. items )
291
- }
275
+ self . visit_mod ( & sub_mod. items )
292
276
}
293
277
294
278
/// Find a file path in the filesystem which corresponds to the given module.
@@ -311,12 +295,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
311
295
Ok ( ( attrs, items, span) ) => Ok ( Some ( SubModKind :: External (
312
296
path,
313
297
DirectoryOwnership :: Owned { relative : None } ,
314
- Module :: new (
315
- span,
316
- Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
317
- Cow :: Owned ( items) ,
318
- & attrs,
319
- ) ,
298
+ Module :: new ( span, Cow :: Owned ( items) , & attrs) ,
320
299
) ) ) ,
321
300
Err ( ParserError :: ParseError ) => Err ( ModuleResolutionError {
322
301
module : mod_name. to_string ( ) ,
@@ -361,24 +340,14 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
361
340
Ok ( Some ( SubModKind :: External (
362
341
file_path,
363
342
dir_ownership,
364
- Module :: new (
365
- span,
366
- Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
367
- Cow :: Owned ( items) ,
368
- & attrs,
369
- ) ,
343
+ Module :: new ( span, Cow :: Owned ( items) , & attrs) ,
370
344
) ) )
371
345
}
372
346
Ok ( ( attrs, items, span) ) => {
373
347
mods_outside_ast. push ( (
374
348
file_path. clone ( ) ,
375
349
dir_ownership,
376
- Module :: new (
377
- span,
378
- Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
379
- Cow :: Owned ( items) ,
380
- & attrs,
381
- ) ,
350
+ Module :: new ( span, Cow :: Owned ( items) , & attrs) ,
382
351
) ) ;
383
352
if should_insert {
384
353
mods_outside_ast. push ( ( file_path, dir_ownership, sub_mod. to_owned ( ) ) ) ;
@@ -501,12 +470,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
501
470
result. push ( (
502
471
actual_path,
503
472
DirectoryOwnership :: Owned { relative : None } ,
504
- Module :: new (
505
- span,
506
- Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
507
- Cow :: Owned ( items) ,
508
- & attrs,
509
- ) ,
473
+ Module :: new ( span, Cow :: Owned ( items) , & attrs) ,
510
474
) )
511
475
}
512
476
result
0 commit comments