@@ -3,6 +3,7 @@ use crate::edition::Edition;
33use crate :: ext:: base:: { DummyResult , ExtCtxt , MacResult , SyntaxExtension } ;
44use crate :: ext:: base:: { NormalTT , TTMacroExpander } ;
55use crate :: ext:: expand:: { AstFragment , AstFragmentKind } ;
6+ use crate :: ext:: hygiene:: Transparency ;
67use crate :: ext:: tt:: macro_parser:: { Success , Error , Failure } ;
78use crate :: ext:: tt:: macro_parser:: { MatchedSeq , MatchedNonterminal } ;
89use crate :: ext:: tt:: macro_parser:: { parse, parse_failure_msg} ;
@@ -375,65 +376,65 @@ pub fn compile(
375376 valid,
376377 } ) ;
377378
378- if body. legacy {
379- let allow_internal_unstable = attr:: find_by_name ( & def. attrs , sym:: allow_internal_unstable)
380- . map ( |attr| attr
381- . meta_item_list ( )
382- . map ( |list| list. iter ( )
383- . filter_map ( |it| {
384- let name = it. ident ( ) . map ( |ident| ident. name ) ;
385- if name. is_none ( ) {
386- sess. span_diagnostic . span_err ( it. span ( ) ,
387- "allow internal unstable expects feature names" )
388- }
389- name
390- } )
391- . collect :: < Vec < Symbol > > ( ) . into ( )
392- )
393- . unwrap_or_else ( || {
394- sess. span_diagnostic . span_warn (
395- attr. span , "allow_internal_unstable expects list of feature names. In the \
396- future this will become a hard error. Please use `allow_internal_unstable(\
397- foo, bar)` to only allow the `foo` and `bar` features",
398- ) ;
399- vec ! [ sym:: allow_internal_unstable_backcompat_hack] . into ( )
379+ let transparency = if attr:: contains_name ( & def. attrs , sym:: rustc_transparent_macro) {
380+ Transparency :: Transparent
381+ } else if body. legacy {
382+ Transparency :: SemiTransparent
383+ } else {
384+ Transparency :: Opaque
385+ } ;
386+
387+ let allow_internal_unstable = attr:: find_by_name ( & def. attrs , sym:: allow_internal_unstable)
388+ . map ( |attr| attr
389+ . meta_item_list ( )
390+ . map ( |list| list. iter ( )
391+ . filter_map ( |it| {
392+ let name = it. ident ( ) . map ( |ident| ident. name ) ;
393+ if name. is_none ( ) {
394+ sess. span_diagnostic . span_err ( it. span ( ) ,
395+ "allow internal unstable expects feature names" )
396+ }
397+ name
400398 } )
401- ) ;
402- let allow_internal_unsafe = attr:: contains_name ( & def. attrs , sym:: allow_internal_unsafe) ;
403- let mut local_inner_macros = false ;
404- if let Some ( macro_export) = attr:: find_by_name ( & def. attrs , sym:: macro_export) {
405- if let Some ( l) = macro_export. meta_item_list ( ) {
406- local_inner_macros = attr:: list_contains_name ( & l, sym:: local_inner_macros) ;
407- }
408- }
399+ . collect :: < Vec < Symbol > > ( ) . into ( )
400+ )
401+ . unwrap_or_else ( || {
402+ sess. span_diagnostic . span_warn (
403+ attr. span , "allow_internal_unstable expects list of feature names. In the \
404+ future this will become a hard error. Please use `allow_internal_unstable(\
405+ foo, bar)` to only allow the `foo` and `bar` features",
406+ ) ;
407+ vec ! [ sym:: allow_internal_unstable_backcompat_hack] . into ( )
408+ } )
409+ ) ;
409410
410- let unstable_feature = attr:: find_stability ( & sess,
411- & def. attrs , def. span ) . and_then ( |stability| {
412- if let attr:: StabilityLevel :: Unstable { issue, .. } = stability. level {
413- Some ( ( stability. feature , issue) )
414- } else {
415- None
416- }
417- } ) ;
418-
419- NormalTT {
420- expander,
421- def_info : Some ( ( def. id , def. span ) ) ,
422- allow_internal_unstable,
423- allow_internal_unsafe,
424- local_inner_macros,
425- unstable_feature,
426- edition,
411+ let allow_internal_unsafe = attr:: contains_name ( & def. attrs , sym:: allow_internal_unsafe) ;
412+
413+ let mut local_inner_macros = false ;
414+ if let Some ( macro_export) = attr:: find_by_name ( & def. attrs , sym:: macro_export) {
415+ if let Some ( l) = macro_export. meta_item_list ( ) {
416+ local_inner_macros = attr:: list_contains_name ( & l, sym:: local_inner_macros) ;
427417 }
428- } else {
429- let is_transparent = attr:: contains_name ( & def. attrs , sym:: rustc_transparent_macro) ;
418+ }
430419
431- SyntaxExtension :: DeclMacro {
432- expander,
433- def_info : Some ( ( def. id , def. span ) ) ,
434- is_transparent,
435- edition,
420+ let unstable_feature = attr:: find_stability ( & sess,
421+ & def. attrs , def. span ) . and_then ( |stability| {
422+ if let attr:: StabilityLevel :: Unstable { issue, .. } = stability. level {
423+ Some ( ( stability. feature , issue) )
424+ } else {
425+ None
436426 }
427+ } ) ;
428+
429+ NormalTT {
430+ expander,
431+ def_info : Some ( ( def. id , def. span ) ) ,
432+ transparency,
433+ allow_internal_unstable,
434+ allow_internal_unsafe,
435+ local_inner_macros,
436+ unstable_feature,
437+ edition,
437438 }
438439}
439440
0 commit comments