Skip to content

Commit cae86ff

Browse files
committed
Add unsafe derive rules and corresponding syntax
This matches what RFC 3715 defines for proc macro derives.
1 parent d38892f commit cae86ff

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

text/3698-declarative-derive-macros.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ If a derive macro mistakenly emits the token stream it was applied to
7070
the duplicate item should hint to the user that the macro was defined
7171
incorrectly, and remind the user that derive macros only append new items.
7272

73+
A `derive()` rule can be marked as `unsafe`: `unsafe derive() (...)
74+
=> { ... }`. Invoking such a derive using a rule marked as unsafe
75+
requires unsafe derive syntax: either
76+
`#[unsafe(derive(DangerousTrait))]` or
77+
`#[derive(unsafe(DangerousTrait))]`. (The latter syntax allows
78+
isolating the `unsafe` to a single derive within a list of
79+
derives.) Invoking an unsafe derive rule without the unsafe derive
80+
syntax will produce a compiler error. Using the unsafe derive
81+
syntax without an unsafe derive will trigger an "unused unsafe"
82+
lint. (RFC 3715 defines the equivalent mechanism for proc macro
83+
derives.)
84+
7385
# Drawbacks
7486
[drawbacks]: #drawbacks
7587

0 commit comments

Comments
 (0)