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

Hygiene affected when using multiple derive #47346

Closed
antoyo opened this issue Jan 11, 2018 · 4 comments
Closed

Hygiene affected when using multiple derive #47346

antoyo opened this issue Jan 11, 2018 · 4 comments
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@antoyo
Copy link
Contributor

antoyo commented Jan 11, 2018

Hi.
I have a proc-macro that generates a macro_rules!.
When I only do:

#[derive(MyCustomDerive)]
struct MyStruct {
}

I can use the generated macro.

However, if I add another custom derive like in:

#[derive(Serialize, MyCustomDerive)]
struct MyStruct {
}

I cannot use the macro anymore…
I get the error:

cannot find macro `my_macro!` in this scope

Strangely, if I do:

#[derive(MyCustomDerive, Serialize)]
struct MyStruct {
}

Putting the serde custom derive after mine fix the issue.
I don't know if it is related to serde or just a bug with multiple custom derives.
Thanks to fix this issue.

@antoyo
Copy link
Contributor Author

antoyo commented Jan 30, 2018

@dtolnay Any info about this?

@dtolnay
Copy link
Member

dtolnay commented Jan 30, 2018

I was able to reproduce this but don't have an explanation.

#[macro_use]
extern crate repro;

#[macro_use]
extern crate serde_derive;

#[derive(Serialize, MyCustomDerive)]
struct MyStruct;

my_macro!();

fn main() {}
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_derive(MyCustomDerive)]
pub fn f(_input: TokenStream) -> TokenStream {
    "
        macro_rules! my_macro {
            () => {}
        }
    ".parse().unwrap()
}

@pietroalbini pietroalbini added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. labels Feb 6, 2018
@Enselic
Copy link
Member

Enselic commented Sep 28, 2023

Triage: I see no strong indication to believe this is a bug in rustc, it seems more likely to be caused by serde, in which case it should be reported there, so let's close this issue. Of course feel free to reopen if it can be demonstrated that this can be reproduced without involving serde.

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
@dtolnay
Copy link
Member

dtolnay commented Sep 28, 2023

This was a rustc bug. It was fixed in Rust 1.39 by #63667.

@Enselic Enselic closed this as completed Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants