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

Unable to serialize or deserialize #2

Closed
lightclient opened this issue Apr 24, 2019 · 11 comments
Closed

Unable to serialize or deserialize #2

lightclient opened this issue Apr 24, 2019 · 11 comments

Comments

@lightclient
Copy link

I'm trying to deserialize params that look like this:

["0x0000000000000000000000000000000000000000"]

using the following struct:

#[derive(Deserialize_tuple)]
 struct BalanceParams {
     address: Address,
}

but I get these errors:

error[E0658]: The attribute `serde` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
  --> src/lib.rs:20:10
   |
20 | #[derive(Deserialize_tuple)]
   |          ^^^^^^^^^^^^^^^^^

error[E0433]: failed to resolve: use of undeclared type or module `serde_derive`
  --> src/lib.rs:20:10
   |
20 | #[derive(Deserialize_tuple)]
   |          ^^^^^^^^^^^^^^^^^ use of undeclared type or module `serde_derive`

error[E0277]: the trait bound `<BalanceParams as serde::de::Deserialize<'de>>::deserialize::Inner: serde::de::Deserialize<'_>` is not satisfied
  --> src/lib.rs:20:10
   |
20 | #[derive(Deserialize_tuple)]
   |          ^^^^^^^^^^^^^^^^^ the trait `serde::de::Deserialize<'_>` is not implemented for `<BalanceParams as serde::de::Deserialize<'de>>::deserialize::Inner`
   |

Even if I use serde (which I don't think I should need to?), the issues remain.

@lightclient
Copy link
Author

If I swap the Address type for i32, I still see the same issue.

@kardeiz
Copy link
Owner

kardeiz commented Apr 24, 2019

@c-o-l-o-r thanks for the issue. I have released a new version 0.2.3 that should resolve the issue.

Previously, this crate did not depend on serde or serde_derive since it doesn't really depend on those crates; it just expands to code in your program, with the assumption that you would bring your own serde and serde_derive.

However, I don't think there is any downside for this crate to depend on serde/serde_derive directly, so I have now done so.

I'm closing this, but please let me know if 0.2.3 doesn't resolve your issue.

@kardeiz kardeiz closed this as completed Apr 24, 2019
@lightclient
Copy link
Author

Thanks for the quick response! I've updated 0.2.3, but now I'm seeing the following error:

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow

Maybe 128 is too low?

#![recursion_limit = "128"]

@kardeiz
Copy link
Owner

kardeiz commented Apr 24, 2019

@c-o-l-o-r can you confirm that it is this proc-macro that is causing the stack overflow?

For example, if you put:

#![recursion_limit = "4096"] 

At the top of your main.rs/lib.rs, does it still crash?

If so, I will increate the recursion limit here to 4096 and cut a new version.

@lightclient
Copy link
Author

@kardeiz, yes if I put #![recursion_limit = "4096"] in my lib.rs it still crashes. 😢

@kardeiz
Copy link
Owner

kardeiz commented Apr 24, 2019

Okay, 0.2.4 has it increased to 4096.

If that doesn't work, I'll need to do some research into the implications of very large recursion limits, or see if there is anything I can do here to avoid running into this...

@lightclient
Copy link
Author

Hmm, it looks like the issue persists. I even cloned this repo and raised the limit to a crazy number. I've been compiling this using the stable channel, but I gave it a shot using nightly and got this:

error: suffixes on a tuple index are invalid
  --> src/lib.rs:20:10
   |
20 | #[derive(Deserialize_tuple)]
   |          ^^^^^^^^^^^^^^^^^ invalid suffix `usize`

error: proc-macro derive produced unparseable tokens
  --> src/lib.rs:20:10
   |
20 | #[derive(Deserialize_tuple)]
   |          ^^^^^^^^^^^^^^^^^

@kardeiz
Copy link
Owner

kardeiz commented Apr 24, 2019

@c-o-l-o-r Your issue on nightly is related to this: rust-lang/rust#59418. It looks like the error is going to be rolled back to a warning tonight (or was last night?; rust-lang/rust#60210). I went ahead and fixed this in 0.2.5.

Can you share your code for Address (and any related de/serialized structs) so I can test the recursion issue?

@kardeiz kardeiz reopened this Apr 24, 2019
@lightclient
Copy link
Author

It doesn't seem like the issue is related to the Address type (although you can find its definition here). I've put together a minimal repo demonstrating my issue. Honestly, it may just be "user error". 😅

https://github.com/c-o-l-o-r/serde_tuple_issue

@kardeiz
Copy link
Owner

kardeiz commented Apr 24, 2019

Aha! I encountered this exact issue a couple months ago: serde-rs/serde#1467.

According to dtolnay, this is a compiler bug: rust-lang/rust#55779.

I don't really understand all the issues around the bug report, but for a quick fix you can put:

#[derive(serde_derive::Deserialize)]
struct Empty {}

somewhere in your code to make the SO go away. Or if you have any other structs that #[derive(Deserialize), that should work as well.

@kardeiz kardeiz closed this as completed Apr 24, 2019
@lightclient
Copy link
Author

Fascinating! Thank you @kardeiz!

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