Uh oh!
There was an error while loading. Please reload this page.
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]
There was a problem hiding this comment.
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.
Without this check, a misspelling like
#[derive(Eqq)]structFoo;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.
sfackler
commented
Mar 7, 2015
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. |
sfackler
commented
Mar 7, 2015
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
bors
commented
Mar 7, 2015
bors
commented
Mar 7, 2015
huonw
commented
Mar 7, 2015
I would appreciate if I can be cc'd on nontrivial |
liigo
commented
Mar 8, 2015
via email
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. |
liigo
commented
Mar 8, 2015
And maybe need an RFC before implementing language changes. (The PR did
|
seanmonstar
commented
Mar 8, 2015
I was surprised to see this without an RFC? |
sfackler
commented
Mar 8, 2015
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. |
kmcallister
commented
Mar 8, 2015
There's lots of stuff in the language reference that's unstable, compiler-specific, or just plain wrong. |
kmcallister
commented
Mar 8, 2015
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, |
kmcallister
commented
Mar 8, 2015
@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 |
steveklabnik
commented
Mar 8, 2015
I was really surprised with this too. |
seanmonstar
commented
Mar 9, 2015
@sfackler Breaking changes aren't what require RFCs. Changes to the language or standard library do. |
kmcallister
commented
Mar 9, 2015
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. |
sfackler
commented
Mar 9, 2015
@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. |
seanmonstar
commented
Mar 9, 2015
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. 🐋 |
liigo
commented
Mar 10, 2015
There is difference: this PR (#23137) try to modify the well-known |
richo
commented
Mar 10, 2015
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. |
huonw
commented
Mar 10, 2015
@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. |
nikomatsakis
commented
Mar 10, 2015
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 |
liigo
commented
Mar 11, 2015
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
deriveis running at the syntax expansion phase.If the
custom_derivefeature 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