@@ -516,6 +516,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
516516 }
517517
518518 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+
519528 let result = match invoc. kind {
520529 InvocationKind :: Bang { .. } => self . expand_bang_invoc ( invoc, ext) ?,
521530 InvocationKind :: Attr { .. } => self . expand_attr_invoc ( invoc, ext) ?,
@@ -549,6 +558,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
549558 } ;
550559
551560 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.
552563 attr:: mark_used ( & attr) ;
553564 }
554565 invoc. expansion_data . mark . set_expn_info ( ExpnInfo {
@@ -1482,34 +1493,14 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
14821493 foreign_item : ast:: ForeignItem ) -> SmallVector < ast:: ForeignItem > {
14831494 let ( attr, traits, foreign_item) = self . classify_item ( foreign_item) ;
14841495
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 ( ) {
15001497 let item = Annotatable :: ForeignItem ( P ( foreign_item) ) ;
15011498 return self . collect_attr ( attr, traits, item, AstFragmentKind :: ForeignItems )
15021499 . make_foreign_items ( ) ;
15031500 }
15041501
15051502 if let ast:: ForeignItemKind :: Macro ( mac) = foreign_item. node {
15061503 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-
15131504 return self . collect_bang ( mac, foreign_item. span , AstFragmentKind :: ForeignItems )
15141505 . make_foreign_items ( ) ;
15151506 }
@@ -1671,7 +1662,6 @@ impl<'feat> ExpansionConfig<'feat> {
16711662 fn enable_custom_derive = custom_derive,
16721663 fn enable_format_args_nl = format_args_nl,
16731664 fn macros_in_extern_enabled = macros_in_extern,
1674- fn custom_attribute_enabled = custom_attribute,
16751665 fn proc_macro_mod = proc_macro_mod,
16761666 fn proc_macro_gen = proc_macro_gen,
16771667 fn proc_macro_expr = proc_macro_expr,
0 commit comments