-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Compiler accepts deriving(Encodable, Decodable) for TreeMaps with non-str keys #8883
Comments
Nominating for milestone 5 (production-ready) |
Correcting myself: I guess the first part of the code (with only type definitions) should compile, so the compiler is doing the right thing there. However, the |
Ah, I know. You're mixing the Encodable/Decodable traits with json's different "ToJson" encoder. Json can do both (to some extent??) (I think this is a mundane issue of extra::json being incorrect, not about deriving and type inference. It's too late for me to disentangle serialize and json at the moment). |
I think the real issue is #9028 |
I think that what we're actually seeing here has something to do with It seems to me that any map with keys which implement Encodable should be valid to encode using It still doesn't look like a deriving vs type inference, but neither does it seem like a problem with different encoding between ToJson and Encoder. I think it's just incorrect implementation details in the |
Just a bug |
The underlying issue here is that even though the JSON spec says objects cannot have non-key strings, but the way |
Encodable has been moved out into its own crate, and so if this issue is still relevant, it belongs there. however, so much has changed since this was originally posted that I'm not even sure if it is. If anyone thinks it is, please open something at https://github.com/rust-lang/rustc-serialize/issues |
Add [`manual_rem_euclid`] lint Closes rust-lang#8883 Adds a lint for checking manual use of `rem_euclid(n)` changelog: Add [`manual_rem_euclid`] lint
The following code should fail to compile:
because there's only an Encodable/Decodable instance for TreeMaps that have ~strs as keys. However, it compiles successfully. Moreover, if I add the following
main()
function:the encode/decode round-trip fails with a JSON decoding error, because the encoder happily prints out a representation of the struct key where a string is required.
It looks like maybe a bug in trait matching where the type parameters are getting ignored? I'm not sure.
The text was updated successfully, but these errors were encountered: