-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Make #[derive(Anything)] into sugar for #[derive_Anything] #23137
Conversation
This is important because attributes can affect expansion.
This is a hack, but I don't think we can do much better as long as `derive` is running at the syntax expansion phase. If the custom_derive feature gate is enabled, this works with user-defined traits and syntax extensions. Without the gate, you can't use e.g. #[derive_Clone] directly, so this does not change the stable language. This commit also cleans up the deriving code somewhat, and forbids some previously-meaningless attribute syntax. For this reason it's technically a [breaking-change]
}; | ||
|
||
if !(is_builtin_trait(tname) || cx.ecfg.enable_custom_derive()) { | ||
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're treating this change as some nice sugar for libraries that are already opting into the unstable plugin infrastructure, do we need a separate feature for this? It should be covered under #![feature(plugin)]
and I'm not sure if there's much benefit to be gained from having a separate feature for custom derives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this check, a misspelling like
#[derive(Eqq)] struct Foo;
will produce a warning or error about unknown attribute derive_Eqq
. And that may not happen if compilation fails first due to a missing trait impl. The gate produces a better error message.
It also controls whether you can use e.g. #[derive_Eq]
directly. We could probably forbid this outright, but I don't see a need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, cool.
We talked about this a bit on IRC. It would be possible to do this by explicitly registering derive plugins that wouldn't involve desugaring. Either solution would need changes made before we can stabilize plugins so I'm fine with this in the interim. |
This is a hack, but I don't think we can do much better as long as `derive` is running at the syntax expansion phase. If the `custom_derive` feature gate is enabled, this works with user-defined traits and syntax extensions. Without the gate, you can't use e.g. `#[derive_Clone]` directly, so this does not change the stable language. To make this effective, we now check gated attributes both before and after macro expansion. This uncovered a number of tests that were missing feature gates. This PR also cleans up the deriving code somewhat, and forbids some previously-meaningless attribute syntax. For this reason it's technically a [breaking-change] r? @sfackler
I would appreciate if I can be cc'd on nontrivial |
I don't like sugars like this. What's the value to have it? And I don't
like we have two very similar styles of derive things.
|
And maybe need an RFC before implementing language changes. (The PR did
|
I was surprised to see this without an RFC? |
It doesn't seem to me like it would need an RFC. It shouldn't cause any user facing behavior to change at all unless they're opting into an unstable feature, and even then the breakage is minor. |
There's lots of stuff in the language reference that's unstable, compiler-specific, or just plain wrong. |
But one is sugar for the other; there's no duplication of meaning. The value is that we can easily register new We could add a special mechanism for hooking into @sfackler and I did talk about long-term directions for this. We probably want a uniform way to refer to syntax-phase stuff (macros, |
@huonw: Sorry about that, I will cc you in the future. I did talk to Niko on IRC and he said this is how he always wanted to do |
I was really surprised with this too. |
@sfackler Breaking changes aren't what require RFCs. Changes to the language or standard library do. |
It's a change that doesn't affect the stable language at all, and only slightly changes the unstable language. If every small change to the unstable language / libraries requires going through the RFC process, then I'll probably stop working on these minor enhancements, because I don't have the patience to push on every tiny fix for weeks and weeks. Unsubscribing, but please let me know if there is a change to the written RFC policy. |
@seanmonstar here are several PRs that altered the syntax extension framework in the last couple of months: #22899 Should all of those have gone through the RFC process? If any tweak to the syntax extension infrastructure requires an RFC, it will completely cripple our ability to iterate on the interface and stabilize it by increasing the time it takes to land a change from a couple of days to 1-2 months. |
Several of those seem to be bug fixes, or altering the internals of the rustc implementation. But whichever. That this caused others to be surprised as well seems to suggests many thought a change like this would have used an RFC. 🐋 |
There is difference: this PR (#23137) try to modify the well-known |
I can't believe I'm letting myself get dragged into this, but: This doesn't change the derive syntax at all. It adds a gate that causes it to desugar, which in turn allows plugin authors to catch and handle those derive tags. Unless I've missed something fairly drastic, this includes no changes to the stable language, and is hidden entirely behind a feature gate. |
@richo is correct. This change affets I don't think this sort of change requires an RFC: we regularly break parts of the plugin API, and any future changes to the custom derive functionality will be in the same vein. |
On Mon, Mar 09, 2015 at 11:00:57PM -0700, Huon Wilson wrote:
I think this is a borderline case. I think that if/when the plugin API (In general, we try to balance the desire to have everything up front As far as the actual design choice goes, personally I agree with kmc (I'm not entirely sure what's the best venue for discussing a change |
Just discuss in a (WIP) PR? (without a quickly r+.) |
This is a hack, but I don't think we can do much better as long as
derive
is running at the syntax expansion phase.If the
custom_derive
feature gate is enabled, this works with user-defined traits and syntax extensions. Without the gate, you can't use e.g.#[derive_Clone]
directly, so this does not change the stable language.To make this effective, we now check gated attributes both before and after macro expansion. This uncovered a number of tests that were missing feature gates.
This PR also cleans up the deriving code somewhat, and forbids some previously-meaningless attribute syntax. For this reason it's technically a
r? @sfackler