@@ -516,6 +516,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
516
516
}
517
517
518
518
fn expand_invoc ( & mut self , invoc : Invocation , ext : & SyntaxExtension ) -> Option < AstFragment > {
519
+ if invoc. fragment_kind == AstFragmentKind :: ForeignItems &&
520
+ !self . cx . ecfg . macros_in_extern_enabled ( ) {
521
+ if let SyntaxExtension :: NonMacroAttr { .. } = * ext { } else {
522
+ emit_feature_err ( & self . cx . parse_sess , "macros_in_extern" ,
523
+ invoc. span ( ) , GateIssue :: Language ,
524
+ "macro invocations in `extern {}` blocks are experimental" ) ;
525
+ }
526
+ }
527
+
519
528
let result = match invoc. kind {
520
529
InvocationKind :: Bang { .. } => self . expand_bang_invoc ( invoc, ext) ?,
521
530
InvocationKind :: Attr { .. } => self . expand_attr_invoc ( invoc, ext) ?,
@@ -549,6 +558,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
549
558
} ;
550
559
551
560
if let NonMacroAttr { mark_used : false } = * ext { } else {
561
+ // Macro attrs are always used when expanded,
562
+ // non-macro attrs are considered used when the field says so.
552
563
attr:: mark_used ( & attr) ;
553
564
}
554
565
invoc. expansion_data . mark . set_expn_info ( ExpnInfo {
@@ -1482,34 +1493,14 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1482
1493
foreign_item : ast:: ForeignItem ) -> SmallVector < ast:: ForeignItem > {
1483
1494
let ( attr, traits, foreign_item) = self . classify_item ( foreign_item) ;
1484
1495
1485
- let explain = if self . cx . ecfg . use_extern_macros_enabled ( ) {
1486
- feature_gate:: EXPLAIN_PROC_MACROS_IN_EXTERN
1487
- } else {
1488
- feature_gate:: EXPLAIN_MACROS_IN_EXTERN
1489
- } ;
1490
-
1491
- if attr. is_some ( ) || !traits. is_empty ( ) {
1492
- if !self . cx . ecfg . macros_in_extern_enabled ( ) &&
1493
- !self . cx . ecfg . custom_attribute_enabled ( ) {
1494
- if let Some ( ref attr) = attr {
1495
- emit_feature_err ( & self . cx . parse_sess , "macros_in_extern" , attr. span ,
1496
- GateIssue :: Language , explain) ;
1497
- }
1498
- }
1499
-
1496
+ if attr. is_some ( ) || !traits. is_empty ( ) {
1500
1497
let item = Annotatable :: ForeignItem ( P ( foreign_item) ) ;
1501
1498
return self . collect_attr ( attr, traits, item, AstFragmentKind :: ForeignItems )
1502
1499
. make_foreign_items ( ) ;
1503
1500
}
1504
1501
1505
1502
if let ast:: ForeignItemKind :: Macro ( mac) = foreign_item. node {
1506
1503
self . check_attributes ( & foreign_item. attrs ) ;
1507
-
1508
- if !self . cx . ecfg . macros_in_extern_enabled ( ) {
1509
- emit_feature_err ( & self . cx . parse_sess , "macros_in_extern" , foreign_item. span ,
1510
- GateIssue :: Language , explain) ;
1511
- }
1512
-
1513
1504
return self . collect_bang ( mac, foreign_item. span , AstFragmentKind :: ForeignItems )
1514
1505
. make_foreign_items ( ) ;
1515
1506
}
@@ -1671,7 +1662,6 @@ impl<'feat> ExpansionConfig<'feat> {
1671
1662
fn enable_custom_derive = custom_derive,
1672
1663
fn enable_format_args_nl = format_args_nl,
1673
1664
fn macros_in_extern_enabled = macros_in_extern,
1674
- fn custom_attribute_enabled = custom_attribute,
1675
1665
fn proc_macro_mod = proc_macro_mod,
1676
1666
fn proc_macro_gen = proc_macro_gen,
1677
1667
fn proc_macro_expr = proc_macro_expr,
0 commit comments