Closed dtolnay closed 6 years ago
Your code seems to compile as written. Playground
Please try minimizing your code to the smallest possible self-contained snippet of code that reproduces your issue. If that isn't sufficient to figure out how to solve the issue, please share a way for me to reproduce what you are seeing and I can take a look. Thanks!
Yeah its strange the exact code I am using is fine in the playground but fails no matter what I do with that exact error locally. I will have to dig a little more and hopefully find more detail to post.
Interesting. I will close the issue for now because there isn't anything actionable for me to look into, and you can let us know when you have minimized the issue in a reproducible way and you believe it needs to be addressed by code changes in Serde.
I found the issue btw. I use cbindgen in my project and that is hard coded to serde_derive version 1.0.21 which was messing everything up. Without that dependency everything is fine.
So not an issue here, but in case anyone else has similar problems I wanted to post this
Had a slightly different error, but this thread came out on top of google search for the error message, so adding my solution in case it helps someone:
For #[serde(flatten)]
I have been getting error: cannot find attribute `serde` in this scope
. Turned out to be quite stupid problem of me not having #[derive(Deserialize, Serialize)]
on my struct.
I stumbled upon the same error and it was due to something else, so contributing here for future googlers:
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
enum Bla {
#[serde(flatten)]
Wrapped(String),
}
fn main() {}
fails with
Compiling playground v0.0.1 (/playground)
error: unknown serde variant attribute `flatten`
--> src/main.rs:5:13
|
5 | #[serde(flatten)]
| ^^^^^^^
error: could not compile `playground` due to previous error
After some research, although it's not stated explicitly in the docs, I figured it wasn't applicable to an enum variant because flatten
inlines keys from a field into the parent struct It is supported only within structs that have named fields, and the field to which it is applied must be a struct or map type"
So no enums (with associated values)
Moved from https://github.com/serde-rs/serde/issues/119:
@mpiannucci is using Serde 1.0.71 and receiving the following error.