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

Deserialize for dynamically sized struct generates invalid code #830

Closed
dtolnay opened this issue Mar 31, 2017 · 1 comment
Closed

Deserialize for dynamically sized struct generates invalid code #830

dtolnay opened this issue Mar 31, 2017 · 1 comment
Assignees
Labels

Comments

@dtolnay
Copy link
Member

dtolnay commented Mar 31, 2017

extern crate serde;

#[macro_use]
extern crate serde_derive;

#[derive(Deserialize)]
struct S {
    last: [u8],
}
error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied in `S`
 --> src/main.rs:6:10
  |
6 | #[derive(Deserialize)]
  |          ^^^^^^^^^^^ within `S`, the trait `std::marker::Sized` is not implemented for `[u8]`
  |
  = note: `[u8]` does not have a constant size known at compile-time
  = note: required because it appears within the type `S`
  = note: required by `serde::Deserialize`
@dtolnay dtolnay added the bug label Mar 31, 2017
@dtolnay
Copy link
Member Author

dtolnay commented Mar 31, 2017

There is no way to implement a working Deserialize for this type because Deserialize requires Self: Sized, but it would be nice to at least detect the case of dynamically sized slice as the last field and fail with a message rather than generating broken code.

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

No branches or pull requests

1 participant