Skip to content

Reordering of attributes passed to rustc_macro_derive #36211

Closed

Description

@dtolnay

(Using rustc from #35957)

Macros 1.1 is reordering attributes in a way that breaks Syntex. If I have the following:

#[derive(Serialize, Deserialize)]
#[serde(bound(deserialize = "T::Owned: Deserialize"))]
struct CowT<'a, T: ?Sized + 'a + ToOwned>(Cow<'a, T>);

It gets passed to my #[rustc_macro_derive(Serialize)] as:

#[serde(bound(deserialize = "T::Owned: Deserialize"))]
#[derive(Deserialize)]
struct CowT<'a, T: ?Sized + 'a + ToOwned>(Cow<'a, T>);

I would expect the #[derive(Deserialize)] to stay above #[serde(...)].

cc @alexcrichton

Activity

  1. alexcrichton commented on Sep 2, 2016

    @alexcrichton
    Member

    Hm I'm not actually sure how to fix this offhand. When the #[derive] syntax extension is running the #[derive] attribute has already been removed, and then when we call the first Serialize implementation we manually push back on the #[derive(Deserialize)]. We could push it at the front instead of the back but I have a feeling that's probably also not the right place :(

    Might require a more intrusive change to #[derive] to not remove the attribute at the beginning.

  2. nrc commented on Sep 2, 2016

    @nrc
    Member

    We could push it at the front instead of the back but I have a feeling that's probably also not the right place

    Why? Putting the remaining derives back where the one we just took out seems like the right thing to do to me.

  3. alexcrichton commented on Sep 2, 2016

    @alexcrichton
    Member

    Oh right yeah we should put the #[derive] attribute back where we found it, but I don't think that information is available via the kind of syntax extension #[derive] is today?

  4. dtolnay commented on Sep 27, 2016

    @dtolnay
    MemberAuthor

    This only affected syntex and is no longer required as we move our rustc_macro away from syntex (serde-rs/serde#548).

  5. dtolnay commented on May 25, 2017

    @dtolnay
    MemberAuthor

    Without syntex this no longer matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions