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

skip attribute doesn't work in tuple struct #2139

Closed
yshui opened this issue Dec 10, 2021 · 1 comment
Closed

skip attribute doesn't work in tuple struct #2139

yshui opened this issue Dec 10, 2021 · 1 comment

Comments

@yshui
Copy link

yshui commented Dec 10, 2021

use serde::{Serialize, Deserialize};

mod cssparser {
    #[derive(Default)]
    pub struct Color;
}

#[derive(Serialize, Deserialize)]
pub struct CSSColor(#[serde(skip)] pub cssparser::Color);

fn main() {}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3a73a0bf1d9ea9ec7051efc415fa909b

error:

error[E0277]: the trait bound `Color: Serialize` is not satisfied
   --> src/main.rs:9:21
    |
9   | pub struct CSSColor(#[serde(skip)] pub cssparser::Color);
    |                     ^ the trait `Serialize` is not implemented for `Color`
    |
note: required by `serialize_newtype_struct`
   --> /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.131/src/ser/mod.rs:898:5
    |
898 | /     fn serialize_newtype_struct<T: ?Sized>(
899 | |         self,
900 | |         name: &'static str,
901 | |         value: &T,
902 | |     ) -> Result<Self::Ok, Self::Error>
903 | |     where
904 | |         T: Serialize;
    | |_____________________^

error[E0277]: the trait bound `Color: Deserialize<'_>` is not satisfied
   --> src/main.rs:9:21
    |
9   | pub struct CSSColor(#[serde(skip)] pub cssparser::Color);
    |                     ^ the trait `Deserialize<'_>` is not implemented for `Color`
    |
note: required by a bound in `_::_serde::Deserialize::deserialize`
   --> /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.131/src/de/mod.rs:539:12
    |
539 |         D: Deserializer<'de>;
    |            ^^^^^^^^^^^^^^^^^ required by this bound in `_::_serde::Deserialize::deserialize`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to 2 previous errors

@dtolnay
Copy link
Member

dtolnay commented Jan 23, 2022

Closing as a duplicate of #2105.

@dtolnay dtolnay closed this as completed Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants