-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Implement declarative (macro_rules!
) derive macros (RFC 3698)
#145208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
(Removing T-clippy and T-rustdoc, because the two commits specific to this PR don't touch them.) |
This comment has been minimized.
This comment has been minimized.
(Marking as "waiting on review" because I'm seeking help with the test failure here.) |
This comment was marked as resolved.
This comment was marked as resolved.
52710b2
to
17f6d0a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
17f6d0a
to
75f119a
Compare
This comment has been minimized.
This comment has been minimized.
(Marking for review now that 145153 is queued.) |
(I'll wait until the rebase anyway.) |
75f119a
to
9e6649e
Compare
9e6649e
to
aa4b01e
Compare
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
aa4b01e
to
a9f6032
Compare
This comment has been minimized.
This comment has been minimized.
Probably because of this FIXME in expand.rs // FIXME: Consider using the derive resolutions (`_exts`)
// instead of enqueuing the derives to be resolved again later. I don't think it's too important to fix, identically looking diagnostics are not shown to users anyway (UI tests suite specifically disables that deduplication). It's suspicious that the |
Oh. Yeah, that would do it; thanks.
Fair enough. It does seem worth fixing for performance reasons if nothing else, but then, the FIXME is there for a reason. I'll ignore it for now, thank you.
That code appears to generate fresh expansions for the enqueuing. I poked pretty extensively at test cases, though, and couldn't find any case where it happened more than twice. So, I think this is worst case 2N, not M*N or N^2. |
This handles various kinds of errors, but does not allow applying the derive yet. This adds the feature gate `macro_derive`.
a9f6032
to
66472e5
Compare
Add infrastructure to apply a derive macro to arguments, consuming and returning a `TokenTree` only. Handle `SyntaxExtensionKind::MacroRules` when expanding a derive, if the macro's kinds support derive. Add tests covering various cases of `macro_rules` derives. Note that due to a pre-existing FIXME in `expand.rs`, derives are re-queued and some errors get emitted twice. Duplicate diagnostic suppression makes them not visible, but the FIXME should still get fixed.
66472e5
to
354fcf2
Compare
@rustbot ready |
@bors r+ |
…enkov Implement declarative (`macro_rules!`) derive macros (RFC 3698) This is a draft for review, and should not be merged yet. This is layered atop rust-lang#145153 , and has only two additional commits atop that. The first handles parsing and provides a test for various parse errors. The second implements expansion and handles application. This implements RFC 3698, "Declarative (`macro_rules!`) derive macros". Tracking issue: rust-lang#143549 This has one remaining issue, which I could use some help debugging: in `tests/ui/macros/macro-rules-derive-error.rs`, the diagnostics for `derive(fn_only)` (for a `fn_only` with no `derive` rules) and `derive(ForwardReferencedDerive)` both get emitted twice, as a duplicate diagnostic. From what I can tell via adding some debugging code, `unresolved_macro_suggestions` is getting called twice from `finalize_macro_resolutions` for each of them, because `self.single_segment_macro_resolutions` has two entries for the macro, with two different `parent_scope` values. I'm not clear on why that happened; it doesn't happen with the equivalent code using attrs. I'd welcome any suggestions for fixing this.
…enkov Implement declarative (`macro_rules!`) derive macros (RFC 3698) This is a draft for review, and should not be merged yet. This is layered atop rust-lang#145153 , and has only two additional commits atop that. The first handles parsing and provides a test for various parse errors. The second implements expansion and handles application. This implements RFC 3698, "Declarative (`macro_rules!`) derive macros". Tracking issue: rust-lang#143549 This has one remaining issue, which I could use some help debugging: in `tests/ui/macros/macro-rules-derive-error.rs`, the diagnostics for `derive(fn_only)` (for a `fn_only` with no `derive` rules) and `derive(ForwardReferencedDerive)` both get emitted twice, as a duplicate diagnostic. From what I can tell via adding some debugging code, `unresolved_macro_suggestions` is getting called twice from `finalize_macro_resolutions` for each of them, because `self.single_segment_macro_resolutions` has two entries for the macro, with two different `parent_scope` values. I'm not clear on why that happened; it doesn't happen with the equivalent code using attrs. I'd welcome any suggestions for fixing this.
This is a draft for review, and should not be merged yet.
This is layered atop #145153 , and has
only two additional commits atop that. The first handles parsing and provides a
test for various parse errors. The second implements expansion and handles
application.
This implements RFC 3698, "Declarative (
macro_rules!
) derive macros".Tracking issue: #143549
This has one remaining issue, which I could use some help debugging: in
tests/ui/macros/macro-rules-derive-error.rs
, the diagnostics forderive(fn_only)
(for afn_only
with noderive
rules) andderive(ForwardReferencedDerive)
both get emitted twice, as a duplicatediagnostic.
From what I can tell via adding some debugging code,
unresolved_macro_suggestions
is getting called twice fromfinalize_macro_resolutions
for each of them, becauseself.single_segment_macro_resolutions
has two entries for the macro, with twodifferent
parent_scope
values. I'm not clear on why that happened; it doesn'thappen with the equivalent code using attrs.
I'd welcome any suggestions for fixing this.