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

Deriving decodable is useless for struct with anonymous fields #15659

Closed
tomaka opened this issue Jul 14, 2014 · 4 comments
Closed

Deriving decodable is useless for struct with anonymous fields #15659

tomaka opened this issue Jul 14, 2014 · 4 comments
Labels
A-syntaxext Area: Syntax extensions

Comments

@tomaka
Copy link
Contributor

tomaka commented Jul 14, 2014

For example:

#[deriving(Decodable)]
struct Duration(int);

The decodable implementation created here tries to decode an object with a field named _field0 and of type int, like { "_field0": 5 }

There two problems with this:

  • Most people won't expect this behavior (I would expect this code to decode a single int, not an object)
  • The fact that the field name is arbitrary makes this trait impl useless anyway

I think that the deriving implementation of decodable for structs with one anonymous field should be equivalent to decoding the type of the field itself.

Structs with multiple anonymous fields are ambiguous, so I think deriving decodable for them should simply trigger a compilation error.

@huonw
Copy link
Member

huonw commented Jul 14, 2014

cc me

@reem
Copy link
Contributor

reem commented Aug 2, 2014

Probably relevant to the newtype RFC (or vice versa). rust-lang/rfcs#186

@bluss
Copy link
Member

bluss commented Oct 1, 2014

Related to #17158 -- there is a separate method for encoding tuple structs, but it is never used by deriving.

@steveklabnik
Copy link
Member

Encode was moved out of tree, so if this is still an issue, please pursue it over at https://github.com/rust-lang/rustc-serialize

bors added a commit to rust-lang-ci/rust that referenced this issue Nov 13, 2023
Add `unused_variables` native diagnostic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

5 participants