@@ -24,7 +24,6 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>;
24
24
/// Represents module with its inner attributes.
25
25
#[ derive( Debug , Clone ) ]
26
26
pub ( crate ) struct Module < ' a > {
27
- ast_mod_kind : Option < & ' a ast:: ModKind > ,
28
27
pub ( crate ) items : & ' a [ rustc_ast:: ptr:: P < ast:: Item > ] ,
29
28
inner_attr : ast:: AttrVec ,
30
29
pub ( crate ) span : Span ,
@@ -33,7 +32,6 @@ pub(crate) struct Module<'a> {
33
32
impl < ' a > Module < ' a > {
34
33
pub ( crate ) fn new (
35
34
mod_span : Span ,
36
- ast_mod_kind : Option < & ' a ast:: ModKind > ,
37
35
mod_items : & ' a [ rustc_ast:: ptr:: P < ast:: Item > ] ,
38
36
mod_attrs : & [ ast:: Attribute ] ,
39
37
) -> Self {
@@ -46,20 +44,15 @@ impl<'a> Module<'a> {
46
44
items : mod_items,
47
45
inner_attr,
48
46
span : mod_span,
49
- ast_mod_kind,
50
47
}
51
48
}
52
49
53
50
pub ( crate ) fn from_item ( item : & ' a ast:: Item ) -> Module < ' a > {
54
- let mod_kind = match & item. kind {
55
- ast:: ItemKind :: Mod ( _, mod_kind) => Some ( mod_kind) ,
56
- _ => None ,
57
- } ;
58
51
let items = match & item. kind {
59
52
ast:: ItemKind :: Mod ( _, ast:: ModKind :: Loaded ( items, ..) ) => & * * items,
60
53
_ => & [ ] ,
61
54
} ;
62
- Module :: new ( item. span , mod_kind , items, & item. attrs )
55
+ Module :: new ( item. span , items, & item. attrs )
63
56
}
64
57
65
58
pub ( crate ) fn attrs ( & self ) -> & [ ast:: Attribute ] {
@@ -70,7 +63,6 @@ impl<'a> Module<'a> {
70
63
/// Maps each module to the corresponding file.
71
64
pub ( crate ) struct ModResolver < ' ast , ' sess > {
72
65
item_arena : & ' ast TypedArena < P < ast:: Item > > ,
73
- mod_kind_arena : & ' ast TypedArena < ast:: ModKind > ,
74
66
parse_sess : & ' sess ParseSess ,
75
67
directory : Directory ,
76
68
file_map : FileModMap < ' ast > ,
@@ -114,14 +106,12 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
114
106
/// Creates a new `ModResolver`.
115
107
pub ( crate ) fn new (
116
108
item_arena : & ' ast TypedArena < P < ast:: Item > > ,
117
- mod_kind_arena : & ' ast TypedArena < ast:: ModKind > ,
118
109
parse_sess : & ' sess ParseSess ,
119
110
directory_ownership : DirectoryOwnership ,
120
111
recursive : bool ,
121
112
) -> Self {
122
113
ModResolver {
123
114
item_arena,
124
- mod_kind_arena,
125
115
directory : Directory {
126
116
path : PathBuf :: new ( ) ,
127
117
ownership : directory_ownership,
@@ -154,7 +144,6 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
154
144
root_filename,
155
145
Module :: new (
156
146
mk_sp ( snippet_provider. start_pos ( ) , snippet_provider. end_pos ( ) ) ,
157
- None ,
158
147
& krate. items ,
159
148
& krate. attrs ,
160
149
) ,
@@ -243,36 +232,21 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
243
232
path : mod_path. parent ( ) . unwrap ( ) . to_path_buf ( ) ,
244
233
ownership : directory_ownership,
245
234
} ;
246
- self . with_directory ( directory, |this| {
247
- this. visit_sub_mod_after_directory_update ( sub_mod)
248
- } ) ?;
235
+ self . with_directory ( directory, |this| this. visit_items ( & sub_mod. items ) ) ?;
249
236
}
250
237
SubModKind :: MultiExternal ( mods) => {
251
238
for ( mod_path, directory_ownership, sub_mod) in mods {
252
239
let directory = Directory {
253
240
path : mod_path. parent ( ) . unwrap ( ) . to_path_buf ( ) ,
254
241
ownership : directory_ownership,
255
242
} ;
256
- self . with_directory ( directory, |this| {
257
- this. visit_sub_mod_after_directory_update ( sub_mod)
258
- } ) ?;
243
+ self . with_directory ( directory, |this| this. visit_items ( & sub_mod. items ) ) ?;
259
244
}
260
245
}
261
246
}
262
247
Ok ( ( ) )
263
248
}
264
249
265
- fn visit_sub_mod_after_directory_update (
266
- & mut self ,
267
- sub_mod : Module < ' ast > ,
268
- ) -> Result < ( ) , ModuleResolutionError > {
269
- if let Some ( ast:: ModKind :: Loaded ( items, _, _) ) = sub_mod. ast_mod_kind {
270
- self . visit_items ( items)
271
- } else {
272
- self . visit_items ( & sub_mod. items )
273
- }
274
- }
275
-
276
250
/// Find a file path in the filesystem which corresponds to the given module.
277
251
fn find_external_module (
278
252
& self ,
@@ -292,12 +266,7 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
292
266
Ok ( ( attrs, items, span) ) => Ok ( Some ( SubModKind :: External (
293
267
path,
294
268
DirectoryOwnership :: Owned { relative : None } ,
295
- Module :: new (
296
- span,
297
- Some ( self . mod_kind_arena . alloc ( ast:: ModKind :: Unloaded ) ) ,
298
- self . item_arena . alloc_from_iter ( items) ,
299
- & attrs,
300
- ) ,
269
+ Module :: new ( span, self . item_arena . alloc_from_iter ( items) , & attrs) ,
301
270
) ) ) ,
302
271
Err ( ParserError :: ParseError ) => Err ( ModuleResolutionError {
303
272
module : mod_name. to_string ( ) ,
@@ -346,24 +315,14 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
346
315
Ok ( Some ( SubModKind :: External (
347
316
file_path,
348
317
dir_ownership,
349
- Module :: new (
350
- span,
351
- Some ( self . mod_kind_arena . alloc ( ast:: ModKind :: Unloaded ) ) ,
352
- self . item_arena . alloc_from_iter ( items) ,
353
- & attrs,
354
- ) ,
318
+ Module :: new ( span, self . item_arena . alloc_from_iter ( items) , & attrs) ,
355
319
) ) )
356
320
}
357
321
Ok ( ( attrs, items, span) ) => {
358
322
mods_outside_ast. push ( (
359
323
file_path. clone ( ) ,
360
324
dir_ownership,
361
- Module :: new (
362
- span,
363
- Some ( self . mod_kind_arena . alloc ( ast:: ModKind :: Unloaded ) ) ,
364
- self . item_arena . alloc_from_iter ( items) ,
365
- & attrs,
366
- ) ,
325
+ Module :: new ( span, self . item_arena . alloc_from_iter ( items) , & attrs) ,
367
326
) ) ;
368
327
if should_insert {
369
328
mods_outside_ast. push ( (
@@ -503,12 +462,7 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
503
462
result. push ( (
504
463
actual_path,
505
464
DirectoryOwnership :: Owned { relative : None } ,
506
- Module :: new (
507
- span,
508
- Some ( self . mod_kind_arena . alloc ( ast:: ModKind :: Unloaded ) ) ,
509
- self . item_arena . alloc_from_iter ( items) ,
510
- & attrs,
511
- ) ,
465
+ Module :: new ( span, self . item_arena . alloc_from_iter ( items) , & attrs) ,
512
466
) )
513
467
}
514
468
result
0 commit comments