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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate definitions when overwriting get with get_copy #74

Closed
pablosichert opened this issue Jan 20, 2021 · 2 comments
Closed

Duplicate definitions when overwriting get with get_copy #74

pablosichert opened this issue Jan 20, 2021 · 2 comments

Comments

@pablosichert
Copy link

Hey @Hoverbear, thanks for this handy crate 馃樃

I noticed that it's not possible to overwrite get with get_copy, e.g.

use getset::{CopyGetters, Getters};

#[derive(Getters, CopyGetters)]
#[get = "pub"]
struct Foo {
    a: String,
    b: String,
    c: String,
    #[get_copy = "pub"]
    d: u64,
}

doesn't compile with

error[E0592]: duplicate definitions with name `d`
 --> src/main.rs:3:19
  |
3 | #[derive(Getters, CopyGetters)]
  |          -------  ^^^^^^^^^^^ duplicate definitions for `d`
  |          |
  |          other definition for `d`
  |
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0592`.
error: could not compile `foo`

The workaround is to use field level attributes on every property:

use getset::{CopyGetters, Getters};

#[derive(Getters, CopyGetters)]
struct Foo {
    #[get = "pub"]
    a: String,
    #[get = "pub"]
    b: String,
    #[get = "pub"]
    c: String,
    #[get_copy = "pub"]
    d: u64,
}
@Hoverbear
Copy link
Collaborator

I'm going to suggest you don't use struct level attributes, sorry. :(

I think its a feature that's come back to bite us.

@pablosichert
Copy link
Author

No problem, works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants