@@ -82,6 +82,40 @@ syntax without an unsafe derive will trigger an "unused unsafe"
82
82
lint. (RFC 3715 defines the equivalent mechanism for proc macro
83
83
derives.)
84
84
85
+ # Reference-level explanation
86
+ [ reference-level-explanation ] : #reference-level-explanation
87
+
88
+ The grammar for macros is extended as follows:
89
+
90
+ > _ MacroRule_ :\
91
+ >   ;  ; ( ` unsafe ` <sup >?</sup > ` derive ` ` ( ` ` ) ` )<sup >?</sup > _ MacroMatcher_ ` => ` _ MacroTranscriber_
92
+
93
+ The _ MacroMatcher_ matches the entire construct the attribute was
94
+ applied to, receiving precisely what a proc-macro-based attribute
95
+ would in the same place.
96
+
97
+ (The empty parentheses after ` derive ` reserve future syntax space
98
+ for derives accepting arguments, at which time they'll be replaced
99
+ by a second _ MacroMatcher_ that matches the arguments.)
100
+
101
+ A derive invocation that uses an ` unsafe derive ` rule will produce
102
+ an error if invoked without using the ` unsafe ` derive syntax. A
103
+ derive invocation that uses an ` derive ` rule (without ` unsafe ` )
104
+ will trigger the "unused unsafe" lint if invoked using the ` unsafe `
105
+ derive syntax. A single derive macro may have both ` derive ` and
106
+ ` unsafe derive ` rules, such as if only some invocations are unsafe.
107
+
108
+ This grammar addition is backwards compatible: previously, a _ MacroRule_ could
109
+ only start with ` ( ` , ` [ ` , or ` { ` , so the parser can easily distinguish rules
110
+ that start with ` derive ` or ` unsafe ` .
111
+
112
+ Adding ` derive ` rules to an existing macro is a semver-compatible change,
113
+ though in practice, it will likely be uncommon.
114
+
115
+ If a user invokes a macro as a derive and that macro does not have any ` derive `
116
+ rules, the compiler should give a clear error stating that the macro is not
117
+ usable as a derive because it does not have any ` derive ` rules.
118
+
85
119
# Drawbacks
86
120
[ drawbacks ] : #drawbacks
87
121
0 commit comments