@@ -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} ;
@@ -374,65 +375,65 @@ pub fn compile(
374375 valid,
375376 } ) ;
376377
377- if body. legacy {
378- let allow_internal_unstable = attr:: find_by_name ( & def. attrs , sym:: allow_internal_unstable)
379- . map ( |attr| attr
380- . meta_item_list ( )
381- . map ( |list| list. iter ( )
382- . filter_map ( |it| {
383- let name = it. ident ( ) . map ( |ident| ident. name ) ;
384- if name. is_none ( ) {
385- sess. span_diagnostic . span_err ( it. span ( ) ,
386- "allow internal unstable expects feature names" )
387- }
388- name
389- } )
390- . collect :: < Vec < Symbol > > ( ) . into ( )
391- )
392- . unwrap_or_else ( || {
393- sess. span_diagnostic . span_warn (
394- attr. span , "allow_internal_unstable expects list of feature names. In the \
395- future this will become a hard error. Please use `allow_internal_unstable(\
396- foo, bar)` to only allow the `foo` and `bar` features",
397- ) ;
398- vec ! [ sym:: allow_internal_unstable_backcompat_hack] . into ( )
378+ let transparency = if attr:: contains_name ( & def. attrs , sym:: rustc_transparent_macro) {
379+ Transparency :: Transparent
380+ } else if body. legacy {
381+ Transparency :: SemiTransparent
382+ } else {
383+ Transparency :: Opaque
384+ } ;
385+
386+ let allow_internal_unstable = attr:: find_by_name ( & def. attrs , sym:: allow_internal_unstable)
387+ . map ( |attr| attr
388+ . meta_item_list ( )
389+ . map ( |list| list. iter ( )
390+ . filter_map ( |it| {
391+ let name = it. ident ( ) . map ( |ident| ident. name ) ;
392+ if name. is_none ( ) {
393+ sess. span_diagnostic . span_err ( it. span ( ) ,
394+ "allow internal unstable expects feature names" )
395+ }
396+ name
399397 } )
400- ) ;
401- let allow_internal_unsafe = attr:: contains_name ( & def. attrs , sym:: allow_internal_unsafe) ;
402- let mut local_inner_macros = false ;
403- if let Some ( macro_export) = attr:: find_by_name ( & def. attrs , sym:: macro_export) {
404- if let Some ( l) = macro_export. meta_item_list ( ) {
405- local_inner_macros = attr:: list_contains_name ( & l, sym:: local_inner_macros) ;
406- }
407- }
398+ . collect :: < Vec < Symbol > > ( ) . into ( )
399+ )
400+ . unwrap_or_else ( || {
401+ sess. span_diagnostic . span_warn (
402+ attr. span , "allow_internal_unstable expects list of feature names. In the \
403+ future this will become a hard error. Please use `allow_internal_unstable(\
404+ foo, bar)` to only allow the `foo` and `bar` features",
405+ ) ;
406+ vec ! [ sym:: allow_internal_unstable_backcompat_hack] . into ( )
407+ } )
408+ ) ;
408409
409- let unstable_feature = attr:: find_stability ( & sess,
410- & def. attrs , def. span ) . and_then ( |stability| {
411- if let attr:: StabilityLevel :: Unstable { issue, .. } = stability. level {
412- Some ( ( stability. feature , issue) )
413- } else {
414- None
415- }
416- } ) ;
417-
418- NormalTT {
419- expander,
420- def_info : Some ( ( def. id , def. span ) ) ,
421- allow_internal_unstable,
422- allow_internal_unsafe,
423- local_inner_macros,
424- unstable_feature,
425- edition,
410+ let allow_internal_unsafe = attr:: contains_name ( & def. attrs , sym:: allow_internal_unsafe) ;
411+
412+ let mut local_inner_macros = false ;
413+ if let Some ( macro_export) = attr:: find_by_name ( & def. attrs , sym:: macro_export) {
414+ if let Some ( l) = macro_export. meta_item_list ( ) {
415+ local_inner_macros = attr:: list_contains_name ( & l, sym:: local_inner_macros) ;
426416 }
427- } else {
428- let is_transparent = attr:: contains_name ( & def. attrs , sym:: rustc_transparent_macro) ;
417+ }
429418
430- SyntaxExtension :: DeclMacro {
431- expander,
432- def_info : Some ( ( def. id , def. span ) ) ,
433- is_transparent,
434- edition,
419+ let unstable_feature = attr:: find_stability ( & sess,
420+ & def. attrs , def. span ) . and_then ( |stability| {
421+ if let attr:: StabilityLevel :: Unstable { issue, .. } = stability. level {
422+ Some ( ( stability. feature , issue) )
423+ } else {
424+ None
435425 }
426+ } ) ;
427+
428+ NormalTT {
429+ expander,
430+ def_info : Some ( ( def. id , def. span ) ) ,
431+ transparency,
432+ allow_internal_unstable,
433+ allow_internal_unsafe,
434+ local_inner_macros,
435+ unstable_feature,
436+ edition,
436437 }
437438}
438439
0 commit comments