@@ -1280,8 +1280,12 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
12801280 }
12811281 ast:: ItemKind :: Mod ( _, ref mut mod_kind) if ident != Ident :: invalid ( ) => {
12821282 let ( file_path, dir_path, dir_ownership) = match mod_kind {
1283- ModKind :: Loaded ( _, Inline :: Yes , _) => {
1283+ ModKind :: Loaded ( _, inline , _) => {
12841284 // Inline `mod foo { ... }`, but we still need to push directories.
1285+ assert ! (
1286+ * inline == Inline :: Yes ,
1287+ "`mod` item is loaded from a file for the second time"
1288+ ) ;
12851289 let ( dir_path, dir_ownership) = mod_dir_path (
12861290 & self . cx . sess ,
12871291 ident,
@@ -1292,11 +1296,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
12921296 item. attrs = attrs;
12931297 ( None , dir_path, dir_ownership)
12941298 }
1295- ModKind :: Loaded ( _, Inline :: No , _) => {
1296- panic ! ( "`mod` item is loaded from a file for the second time" )
1297- }
12981299 ModKind :: Unloaded => {
12991300 // We have an outline `mod foo;` so we need to parse the file.
1301+ let old_attrs_len = attrs. len ( ) ;
13001302 let ParsedExternalMod {
13011303 mut items,
13021304 inner_span,
@@ -1318,8 +1320,13 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13181320
13191321 * mod_kind = ModKind :: Loaded ( items, Inline :: No , inner_span) ;
13201322 item. attrs = attrs;
1321- // File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure.
1322- item = configure ! ( self , item) ;
1323+ if item. attrs . len ( ) > old_attrs_len {
1324+ // If we loaded an out-of-line module and added some inner attributes,
1325+ // then we need to re-configure it.
1326+ // FIXME: Attributes also need to be recollected
1327+ // for resolution and expansion.
1328+ item = configure ! ( self , item) ;
1329+ }
13231330 ( Some ( file_path) , dir_path, dir_ownership)
13241331 }
13251332 } ;
0 commit comments