@@ -1280,8 +1280,12 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
1280
1280
}
1281
1281
ast:: ItemKind :: Mod ( _, ref mut mod_kind) if ident != Ident :: invalid ( ) => {
1282
1282
let ( file_path, dir_path, dir_ownership) = match mod_kind {
1283
- ModKind :: Loaded ( _, Inline :: Yes , _) => {
1283
+ ModKind :: Loaded ( _, inline , _) => {
1284
1284
// 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
+ ) ;
1285
1289
let ( dir_path, dir_ownership) = mod_dir_path (
1286
1290
& self . cx . sess ,
1287
1291
ident,
@@ -1292,11 +1296,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
1292
1296
item. attrs = attrs;
1293
1297
( None , dir_path, dir_ownership)
1294
1298
}
1295
- ModKind :: Loaded ( _, Inline :: No , _) => {
1296
- panic ! ( "`mod` item is loaded from a file for the second time" )
1297
- }
1298
1299
ModKind :: Unloaded => {
1299
1300
// We have an outline `mod foo;` so we need to parse the file.
1301
+ let old_attrs_len = attrs. len ( ) ;
1300
1302
let ParsedExternalMod {
1301
1303
mut items,
1302
1304
inner_span,
@@ -1318,8 +1320,13 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
1318
1320
1319
1321
* mod_kind = ModKind :: Loaded ( items, Inline :: No , inner_span) ;
1320
1322
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
+ }
1323
1330
( Some ( file_path) , dir_path, dir_ownership)
1324
1331
}
1325
1332
} ;
0 commit comments