@@ -14,9 +14,10 @@ use ast::{self, Attribute, Name, PatKind, MetaItem};
1414use attr:: HasAttrs ;
1515use codemap:: { self , CodeMap , Spanned , respan} ;
1616use syntax_pos:: { Span , MultiSpan , DUMMY_SP } ;
17+ use edition:: Edition ;
1718use errors:: { DiagnosticBuilder , DiagnosticId } ;
1819use ext:: expand:: { self , Expansion , Invocation } ;
19- use ext:: hygiene:: { Mark , SyntaxContext } ;
20+ use ext:: hygiene:: { self , Mark , SyntaxContext } ;
2021use fold:: { self , Folder } ;
2122use parse:: { self , parser, DirectoryOwnership } ;
2223use parse:: token;
@@ -586,13 +587,13 @@ pub enum SyntaxExtension {
586587 MultiModifier ( Box < MultiItemModifier + sync:: Sync + sync:: Send > ) ,
587588
588589 /// A function-like procedural macro. TokenStream -> TokenStream.
589- ProcMacro ( Box < ProcMacro + sync:: Sync + sync:: Send > ) ,
590+ ProcMacro ( Box < ProcMacro + sync:: Sync + sync:: Send > , Edition ) ,
590591
591592 /// An attribute-like procedural macro. TokenStream, TokenStream -> TokenStream.
592593 /// The first TokenSteam is the attribute, the second is the annotated item.
593594 /// Allows modification of the input items and adding new items, similar to
594595 /// MultiModifier, but uses TokenStreams, rather than AST nodes.
595- AttrProcMacro ( Box < AttrProcMacro + sync:: Sync + sync:: Send > ) ,
596+ AttrProcMacro ( Box < AttrProcMacro + sync:: Sync + sync:: Send > , Edition ) ,
596597
597598 /// A normal, function-like syntax extension.
598599 ///
@@ -608,6 +609,8 @@ pub enum SyntaxExtension {
608609 allow_internal_unsafe : bool ,
609610 /// The macro's feature name if it is unstable, and the stability feature
610611 unstable_feature : Option < ( Symbol , u32 ) > ,
612+ /// Edition of the crate in which the macro is defined
613+ edition : Edition ,
611614 } ,
612615
613616 /// A function-like syntax extension that has an extra ident before
@@ -619,17 +622,16 @@ pub enum SyntaxExtension {
619622 /// The input is the annotated item.
620623 /// Allows generating code to implement a Trait for a given struct
621624 /// or enum item.
622- ProcMacroDerive ( Box < MultiItemModifier +
623- sync:: Sync +
624- sync:: Send > , Vec < Symbol > /* inert attribute names */ ) ,
625+ ProcMacroDerive ( Box < MultiItemModifier + sync:: Sync + sync:: Send > ,
626+ Vec < Symbol > /* inert attribute names */ , Edition ) ,
625627
626628 /// An attribute-like procedural macro that derives a builtin trait.
627629 BuiltinDerive ( BuiltinDeriveFn ) ,
628630
629631 /// A declarative macro, e.g. `macro m() {}`.
630632 ///
631633 /// The second element is the definition site span.
632- DeclMacro ( Box < TTMacroExpander + sync:: Sync + sync:: Send > , Option < ( ast:: NodeId , Span ) > ) ,
634+ DeclMacro ( Box < TTMacroExpander + sync:: Sync + sync:: Send > , Option < ( ast:: NodeId , Span ) > , Edition ) ,
633635}
634636
635637impl SyntaxExtension {
@@ -660,6 +662,21 @@ impl SyntaxExtension {
660662 _ => false ,
661663 }
662664 }
665+
666+ pub fn edition ( & self ) -> Edition {
667+ match * self {
668+ SyntaxExtension :: NormalTT { edition, .. } |
669+ SyntaxExtension :: DeclMacro ( .., edition) |
670+ SyntaxExtension :: ProcMacro ( .., edition) |
671+ SyntaxExtension :: AttrProcMacro ( .., edition) |
672+ SyntaxExtension :: ProcMacroDerive ( .., edition) => edition,
673+ // Unstable legacy stuff
674+ SyntaxExtension :: IdentTT ( ..) |
675+ SyntaxExtension :: MultiDecorator ( ..) |
676+ SyntaxExtension :: MultiModifier ( ..) |
677+ SyntaxExtension :: BuiltinDerive ( ..) => hygiene:: default_edition ( ) ,
678+ }
679+ }
663680}
664681
665682pub type NamedSyntaxExtension = ( Name , SyntaxExtension ) ;
0 commit comments