@@ -12,8 +12,8 @@ use rustc_ast::ptr::P;
12
12
use rustc_ast:: token;
13
13
use rustc_ast:: tokenstream:: TokenStream ;
14
14
use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
15
- use rustc_ast:: { AttrItem , AttrStyle , Block , ItemKind , LitKind , MacArgs } ;
16
- use rustc_ast:: { MacCallStmt , MacStmtStyle , MetaItemKind , NestedMetaItem } ;
15
+ use rustc_ast:: { AttrItem , AttrStyle , Block , Inline , ItemKind , LitKind , MacArgs } ;
16
+ use rustc_ast:: { MacCallStmt , MacStmtStyle , MetaItemKind , ModKind , NestedMetaItem } ;
17
17
use rustc_ast:: { NodeId , PatKind , Path , StmtKind , Unsafe } ;
18
18
use rustc_ast_pretty:: pprust;
19
19
use rustc_attr:: { self as attr, is_builtin_attr, HasAttrs } ;
@@ -367,12 +367,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
367
367
let krate_item = AstFragment :: Items ( smallvec ! [ P ( ast:: Item {
368
368
attrs: krate. attrs,
369
369
span: krate. span,
370
- kind: ast:: ItemKind :: Mod ( ast:: Mod {
371
- inner: krate. span,
372
- unsafety: Unsafe :: No ,
373
- items: krate. items,
374
- inline: true
375
- } ) ,
370
+ kind: ast:: ItemKind :: Mod (
371
+ Unsafe :: No ,
372
+ ModKind :: Loaded ( krate. items, Inline :: Yes , krate. span)
373
+ ) ,
376
374
ident: Ident :: invalid( ) ,
377
375
id: ast:: DUMMY_NODE_ID ,
378
376
vis: ast:: Visibility {
@@ -384,9 +382,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
384
382
} ) ] ) ;
385
383
386
384
match self . fully_expand_fragment ( krate_item) . make_items ( ) . pop ( ) . map ( P :: into_inner) {
387
- Some ( ast:: Item { attrs, kind : ast:: ItemKind :: Mod ( module) , .. } ) => {
385
+ Some ( ast:: Item {
386
+ attrs,
387
+ kind : ast:: ItemKind :: Mod ( _, ModKind :: Loaded ( items, ..) ) ,
388
+ ..
389
+ } ) => {
388
390
krate. attrs = attrs;
389
- krate. items = module . items ;
391
+ krate. items = items;
390
392
}
391
393
None => {
392
394
// Resolution failed so we return an empty expansion
@@ -809,7 +811,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
809
811
impl < ' ast , ' a > Visitor < ' ast > for GateProcMacroInput < ' a > {
810
812
fn visit_item ( & mut self , item : & ' ast ast:: Item ) {
811
813
match & item. kind {
812
- ast:: ItemKind :: Mod ( module) if !module. inline => {
814
+ ast:: ItemKind :: Mod ( _, mod_kind)
815
+ if !matches ! ( mod_kind, ModKind :: Loaded ( _, Inline :: Yes , _) ) =>
816
+ {
813
817
feature_err (
814
818
self . parse_sess ,
815
819
sym:: proc_macro_hygiene,
@@ -1266,47 +1270,47 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
1266
1270
_ => unreachable ! ( ) ,
1267
1271
} )
1268
1272
}
1269
- ast:: ItemKind :: Mod ( ref mut old_mod @ ast :: Mod { .. } ) if ident != Ident :: invalid ( ) => {
1273
+ ast:: ItemKind :: Mod ( _ , ref mut mod_kind ) if ident != Ident :: invalid ( ) => {
1270
1274
let sess = & self . cx . sess . parse_sess ;
1271
1275
let orig_ownership = self . cx . current_expansion . directory_ownership ;
1272
1276
let mut module = ( * self . cx . current_expansion . module ) . clone ( ) ;
1273
1277
1274
1278
let pushed = & mut false ; // Record `parse_external_mod` pushing so we can pop.
1275
1279
let dir = Directory { ownership : orig_ownership, path : module. directory } ;
1276
- let Directory { ownership, path } = if old_mod. inline {
1277
- // Inline `mod foo { ... }`, but we still need to push directories.
1278
- item. attrs = attrs;
1279
- push_directory ( & self . cx . sess , ident, & item. attrs , dir)
1280
- } else {
1281
- // We have an outline `mod foo;` so we need to parse the file.
1282
- let ( ast:: Mod { unsafety, inline, items, inner } , dir) = parse_external_mod (
1283
- & self . cx . sess ,
1284
- ident,
1285
- span,
1286
- old_mod. unsafety ,
1287
- dir,
1288
- & mut attrs,
1289
- pushed,
1290
- ) ;
1291
-
1292
- let krate = ast:: Crate { attrs, items, span : inner, proc_macros : vec ! [ ] } ;
1293
- if let Some ( extern_mod_loaded) = self . cx . extern_mod_loaded {
1294
- extern_mod_loaded ( & krate, ident) ;
1280
+ let Directory { ownership, path } = match mod_kind {
1281
+ ModKind :: Loaded ( _, Inline :: Yes , _) => {
1282
+ // Inline `mod foo { ... }`, but we still need to push directories.
1283
+ item. attrs = attrs;
1284
+ push_directory ( & self . cx . sess , ident, & item. attrs , dir)
1285
+ }
1286
+ ModKind :: Loaded ( _, Inline :: No , _) => {
1287
+ panic ! ( "`mod` item is loaded from a file for the second time" )
1295
1288
}
1289
+ ModKind :: Unloaded => {
1290
+ // We have an outline `mod foo;` so we need to parse the file.
1291
+ let ( items, inner_span, dir) =
1292
+ parse_external_mod ( & self . cx . sess , ident, span, dir, & mut attrs, pushed) ;
1293
+
1294
+ let krate =
1295
+ ast:: Crate { attrs, items, span : inner_span, proc_macros : vec ! [ ] } ;
1296
+ if let Some ( extern_mod_loaded) = self . cx . extern_mod_loaded {
1297
+ extern_mod_loaded ( & krate, ident) ;
1298
+ }
1296
1299
1297
- * old_mod = ast:: Mod { unsafety, inline, items : krate. items , inner } ;
1298
- item. attrs = krate. attrs ;
1299
- // File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure.
1300
- item = match self . configure ( item) {
1301
- Some ( node) => node,
1302
- None => {
1303
- if * pushed {
1304
- sess. included_mod_stack . borrow_mut ( ) . pop ( ) ;
1300
+ * mod_kind = ModKind :: Loaded ( krate. items , Inline :: No , inner_span) ;
1301
+ item. attrs = krate. attrs ;
1302
+ // File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure.
1303
+ item = match self . configure ( item) {
1304
+ Some ( node) => node,
1305
+ None => {
1306
+ if * pushed {
1307
+ sess. included_mod_stack . borrow_mut ( ) . pop ( ) ;
1308
+ }
1309
+ return Default :: default ( ) ;
1305
1310
}
1306
- return Default :: default ( ) ;
1307
- }
1308
- } ;
1309
- dir
1311
+ } ;
1312
+ dir
1313
+ }
1310
1314
} ;
1311
1315
1312
1316
// Set the module info before we flat map.
0 commit comments