@@ -549,60 +549,78 @@ impl MacroKind {
549
549
550
550
/// An enum representing the different kinds of syntax extensions.
551
551
pub enum SyntaxExtension {
552
- /// A trivial "extension" that does nothing, only keeps the attribute and marks it as known.
553
- NonMacroAttr { mark_used : bool } ,
554
-
555
- /// A syntax extension that is attached to an item and modifies it
556
- /// in-place. Also allows decoration, i.e., creating new items.
557
- MultiModifier ( Box < dyn MultiItemModifier + sync:: Sync + sync:: Send > ) ,
558
-
559
- /// A function-like procedural macro. TokenStream -> TokenStream.
552
+ /// A token-based function-like macro.
560
553
ProcMacro {
554
+ /// An expander with signature TokenStream -> TokenStream.
561
555
expander : Box < dyn ProcMacro + sync:: Sync + sync:: Send > ,
562
- /// Whitelist of unstable features that are treated as stable inside this macro
556
+ /// Whitelist of unstable features that are treated as stable inside this macro.
563
557
allow_internal_unstable : Option < Lrc < [ Symbol ] > > ,
558
+ /// Edition of the crate in which this macro is defined.
564
559
edition : Edition ,
565
560
} ,
566
561
567
- /// An attribute-like procedural macro. TokenStream, TokenStream -> TokenStream.
568
- /// The first TokenSteam is the attribute, the second is the annotated item.
569
- /// Allows modification of the input items and adding new items, similar to
570
- /// MultiModifier, but uses TokenStreams, rather than AST nodes.
571
- AttrProcMacro ( Box < dyn AttrProcMacro + sync:: Sync + sync:: Send > , Edition ) ,
572
-
573
- /// A normal, function-like syntax extension.
574
- ///
575
- /// `bytes!` is a `NormalTT`.
562
+ /// An AST-based function-like macro.
576
563
NormalTT {
564
+ /// An expander with signature TokenStream -> AST.
577
565
expander : Box < dyn TTMacroExpander + sync:: Sync + sync:: Send > ,
566
+ /// Some info about the macro's definition point.
578
567
def_info : Option < ( ast:: NodeId , Span ) > ,
568
+ /// Hygienic properties of identifiers produced by this macro.
579
569
transparency : Transparency ,
580
- /// Whether the contents of the macro can
581
- /// directly use `#[unstable]` things.
582
- ///
583
- /// Only allows things that require a feature gate in the given whitelist
570
+ /// Whitelist of unstable features that are treated as stable inside this macro.
584
571
allow_internal_unstable : Option < Lrc < [ Symbol ] > > ,
585
- /// Whether the contents of the macro can use `unsafe`
586
- /// without triggering the `unsafe_code` lint.
572
+ /// Suppresses the `unsafe_code` lint for code produced by this macro.
587
573
allow_internal_unsafe : bool ,
588
- /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`)
589
- /// for a given macro.
574
+ /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro.
590
575
local_inner_macros : bool ,
591
- /// The macro's feature name if it is unstable, and the stability feature
576
+ /// The macro's feature name and tracking issue number if it is unstable.
592
577
unstable_feature : Option < ( Symbol , u32 ) > ,
593
- /// Edition of the crate in which the macro is defined
578
+ /// Edition of the crate in which this macro is defined.
594
579
edition : Edition ,
595
580
} ,
596
581
597
- /// An attribute-like procedural macro. TokenStream -> TokenStream.
598
- /// The input is the annotated item.
599
- /// Allows generating code to implement a Trait for a given struct
600
- /// or enum item.
601
- ProcMacroDerive ( Box < dyn MultiItemModifier + sync:: Sync + sync:: Send > ,
602
- Vec < Symbol > /* inert attribute names */ , Edition ) ,
582
+ /// A token-based attribute macro.
583
+ AttrProcMacro (
584
+ /// An expander with signature (TokenStream, TokenStream) -> TokenStream.
585
+ /// The first TokenSteam is the attribute itself, the second is the annotated item.
586
+ /// The produced TokenSteam replaces the input TokenSteam.
587
+ Box < dyn AttrProcMacro + sync:: Sync + sync:: Send > ,
588
+ /// Edition of the crate in which this macro is defined.
589
+ Edition ,
590
+ ) ,
591
+
592
+ /// An AST-based attribute macro.
593
+ MultiModifier (
594
+ /// An expander with signature (AST, AST) -> AST.
595
+ /// The first AST fragment is the attribute itself, the second is the annotated item.
596
+ /// The produced AST fragment replaces the input AST fragment.
597
+ Box < dyn MultiItemModifier + sync:: Sync + sync:: Send > ,
598
+ ) ,
599
+
600
+ /// A trivial attribute "macro" that does nothing,
601
+ /// only keeps the attribute and marks it as known.
602
+ NonMacroAttr {
603
+ /// Suppresses the `unused_attributes` lint for this attribute.
604
+ mark_used : bool ,
605
+ } ,
603
606
604
- /// An attribute-like procedural macro that derives a builtin trait.
605
- BuiltinDerive ( Box < dyn MultiItemModifier + sync:: Sync + sync:: Send > ) ,
607
+ /// A token-based derive macro.
608
+ ProcMacroDerive (
609
+ /// An expander with signature TokenStream -> TokenStream (not yet).
610
+ /// The produced TokenSteam is appended to the input TokenSteam.
611
+ Box < dyn MultiItemModifier + sync:: Sync + sync:: Send > ,
612
+ /// Names of helper attributes registered by this macro.
613
+ Vec < Symbol > ,
614
+ /// Edition of the crate in which this macro is defined.
615
+ Edition ,
616
+ ) ,
617
+
618
+ /// An AST-based derive macro.
619
+ BuiltinDerive (
620
+ /// An expander with signature AST -> AST.
621
+ /// The produced AST fragment is appended to the input AST fragment.
622
+ Box < dyn MultiItemModifier + sync:: Sync + sync:: Send > ,
623
+ ) ,
606
624
}
607
625
608
626
impl SyntaxExtension {
0 commit comments