@@ -12,8 +12,8 @@ use rustc_ast::ptr::P;
1212use rustc_ast:: token;
1313use rustc_ast:: tokenstream:: TokenStream ;
1414use 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 } ;
1717use rustc_ast:: { NodeId , PatKind , Path , StmtKind , Unsafe } ;
1818use rustc_ast_pretty:: pprust;
1919use rustc_attr:: { self as attr, is_builtin_attr, HasAttrs } ;
@@ -367,12 +367,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
367367 let krate_item = AstFragment :: Items ( smallvec ! [ P ( ast:: Item {
368368 attrs: krate. attrs,
369369 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+ ) ,
376374 ident: Ident :: invalid( ) ,
377375 id: ast:: DUMMY_NODE_ID ,
378376 vis: ast:: Visibility {
@@ -384,9 +382,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
384382 } ) ] ) ;
385383
386384 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+ } ) => {
388390 krate. attrs = attrs;
389- krate. items = module . items ;
391+ krate. items = items;
390392 }
391393 None => {
392394 // Resolution failed so we return an empty expansion
@@ -809,7 +811,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
809811 impl < ' ast , ' a > Visitor < ' ast > for GateProcMacroInput < ' a > {
810812 fn visit_item ( & mut self , item : & ' ast ast:: Item ) {
811813 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+ {
813817 feature_err (
814818 self . parse_sess ,
815819 sym:: proc_macro_hygiene,
@@ -1266,47 +1270,47 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
12661270 _ => unreachable ! ( ) ,
12671271 } )
12681272 }
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 ( ) => {
12701274 let sess = & self . cx . sess . parse_sess ;
12711275 let orig_ownership = self . cx . current_expansion . directory_ownership ;
12721276 let mut module = ( * self . cx . current_expansion . module ) . clone ( ) ;
12731277
12741278 let pushed = & mut false ; // Record `parse_external_mod` pushing so we can pop.
12751279 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" )
12951288 }
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+ }
12961299
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 ( ) ;
13051310 }
1306- return Default :: default ( ) ;
1307- }
1308- } ;
1309- dir
1311+ } ;
1312+ dir
1313+ }
13101314 } ;
13111315
13121316 // Set the module info before we flat map.
0 commit comments