Skip to content
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

RFC: Allow external #[deriving(...)] implementations #480

Closed
rust-highfive opened this Issue Nov 24, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@rust-highfive
Copy link

rust-highfive commented Nov 24, 2014

Issue by sfackler
Sunday Jan 26, 2014 at 06:47 GMT

For earlier discussion, see rust-lang/rust#11813

This issue was labelled with: A-syntaxext in the Rust repository


Background

Now that #11151 has landed, third-party code can define syntax extensions just as the compiler does - with the exception of adding new types to #[deriving(..)]. It is possible to write an extension that does the same thing as #[deriving(..)] does, but it has to be implemented as #[deriving_MyTrait] instead of #[deriving(MyTrait)]. This unfortunate, especially when a user wants to derive multiple first- and third-party traits:

#[deriving(Clone, Eq, Ord)]
#[deriving_Foo]
#[deriving_Bar]
#[deriving_Baz]
pub struct Blah {
    ...
}

The repetition of multiple #[deriving_Foo]s was the driving force for the creation of #[deriving(..)] in the first place!

The Proposal

Change the signature of the macro registration function to this:

pub type MacroCrateRegistrationFun =
    fn(macro_callback: |Name, SyntaxExtension|,
       deriving_callback: |~str, DerivingExtension|);

#[deriving(..)] types will be registered by the extension infrastructure just like other syntax extensions are.

This does have a (potentially) large downside: the extension infrastructure will have to have special knowledge of #[deriving(..)] to keep track of the registered extensions. I think it's probably worth it, and there are already some other "special" extensions like trace_macros!. What does everyone else think?

@Manishearth

This comment has been minimized.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Feb 11, 2016

I believe this has since been implemented, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.