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

#[serde(skip)] is ignored on a 1-field tuple struct #2105

Open
kpreid opened this issue Oct 18, 2021 · 0 comments · May be fixed by #2520
Open

#[serde(skip)] is ignored on a 1-field tuple struct #2105

kpreid opened this issue Oct 18, 2021 · 0 comments · May be fixed by #2520
Labels

Comments

@kpreid
Copy link

kpreid commented Oct 18, 2021

With serde v1.0.130, applying #[serde(skip)] to the sole field of a tuple struct is silently ignored, so that the field is serialized (and hence required to be serializable). This seems like a bug: it should result in the struct being treated the same as one which actually has no fields, or if there is some reason this should not be the interpretation, there should be an error or warning.

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct Skip1(#[serde(skip)] i32);

#[derive(Serialize, Deserialize)]
struct Skip2(#[serde(skip)] i32, i32);

#[derive(Serialize, Deserialize)]
struct ActuallyEmpty();

fn main() {
    println!(
        "{}",
        serde_json::to_string(&(
            Skip1(101),
            Skip2(201, 202),
            ActuallyEmpty(),
        )).unwrap()
    );
}

Expected output: [[], [202], []]

Actual output: [101, [202], []]

@dtolnay dtolnay added the derive label Jul 9, 2023
Mingun added a commit to Mingun/serde that referenced this issue Jul 21, 2023
…r to Tuple0() struct

A side-effect: Tuple2as1(Skipped, x) now also can be deserialized using visit_newtype_struct

Changes in generated code (see the file attached to PR):
  Tuple1as0:
  Tuple1as0Default:
  Tuple1as0With:
    removed visit_newtype_struct, *_newtype_struct -> *_tuple_struct(0)

  Tuple2as1:
  Tuple2as1Default:
  Tuple2as1With:
    added visit_newtype_struct

This commit fixes compilation error and actually fixes the issue as it was reported in serde-rs#2105
Mingun added a commit to Mingun/serde that referenced this issue Jul 28, 2023
…r to Tuple0() struct

A side-effect: Tuple2as1(Skipped, x) now also can be deserialized using visit_newtype_struct

Changes in generated code (see the file attached to PR):
  Tuple1as0:
  Tuple1as0Default:
  Tuple1as0With:
    removed visit_newtype_struct, *_newtype_struct -> *_tuple_struct(0)

  Tuple2as1:
  Tuple2as1Default:
  Tuple2as1With:
    added visit_newtype_struct

This commit fixes compilation error and actually fixes the issue as it was reported in serde-rs#2105
Mingun added a commit to Mingun/serde that referenced this issue Jul 31, 2023
…r to Tuple0() struct

A side-effect: Tuple2as1(Skipped, x) now also can be deserialized using visit_newtype_struct

Changes in generated code (see the file attached to PR):
  Tuple1as0:
  Tuple1as0Default:
  Tuple1as0With:
    removed visit_newtype_struct, *_newtype_struct -> *_tuple_struct(0)

  Tuple2as1:
  Tuple2as1Default:
  Tuple2as1With:
    added visit_newtype_struct

This commit fixes compilation error and actually fixes the issue as it was reported in serde-rs#2105
Mingun added a commit to Mingun/serde that referenced this issue Aug 2, 2023
…r to Tuple0() struct

A side-effect: Tuple2as1(Skipped, x) now also can be deserialized using visit_newtype_struct

Changes in generated code (see the file attached to PR):
  Tuple1as0:
  Tuple1as0Default:
  Tuple1as0With:
    removed visit_newtype_struct, *_newtype_struct -> *_tuple_struct(0)

  Tuple2as1:
  Tuple2as1Default:
  Tuple2as1With:
    added visit_newtype_struct

This commit fixes compilation error and actually fixes the issue as it was reported in serde-rs#2105
Mingun added a commit to Mingun/serde that referenced this issue Aug 6, 2023
…r to Tuple0() struct

A side-effect: Tuple2as1(Skipped, x) now also can be deserialized using visit_newtype_struct

Changes in generated code (see the file attached to PR):
  Tuple1as0:
  Tuple1as0Default:
  Tuple1as0With:
    removed visit_newtype_struct, *_newtype_struct -> *_tuple_struct(0)

  Tuple2as1:
  Tuple2as1Default:
  Tuple2as1With:
    added visit_newtype_struct

This commit fixes compilation error and actually fixes the issue as it was reported in serde-rs#2105
Mingun added a commit to Mingun/serde that referenced this issue Aug 7, 2023
…r to Tuple0() struct

A side-effect: Tuple2as1(Skipped, x) now also can be deserialized using visit_newtype_struct

Changes in generated code (see the file attached to PR):
  Tuple1as0:
  Tuple1as0Default:
  Tuple1as0With:
    removed visit_newtype_struct, *_newtype_struct -> *_tuple_struct(0)

  Tuple2as1:
  Tuple2as1Default:
  Tuple2as1With:
    added visit_newtype_struct

This commit fixes compilation error and actually fixes the issue as it was reported in serde-rs#2105
Mingun added a commit to Mingun/serde that referenced this issue Jul 23, 2024
…r to Tuple0() struct

A side-effect: Tuple2as1(Skipped, x) now also can be deserialized using visit_newtype_struct

Changes in generated code (see the file attached to PR):
  Tuple1as0:
  Tuple1as0Default:
  Tuple1as0With:
    removed visit_newtype_struct, *_newtype_struct -> *_tuple_struct(0)

  Tuple2as1:
  Tuple2as1Default:
  Tuple2as1With:
    added visit_newtype_struct

This commit fixes compilation error and actually fixes the issue as it was reported in serde-rs#2105
Mingun added a commit to Mingun/serde that referenced this issue Oct 25, 2024
…r to Tuple0() struct

A side-effect: Tuple2as1(Skipped, x) now also can be deserialized using visit_newtype_struct

Changes in generated code (see the file attached to PR):
  Tuple1as0:
  Tuple1as0Default:
  Tuple1as0With:
    removed visit_newtype_struct, *_newtype_struct -> *_tuple_struct(0)

  Tuple2as1:
  Tuple2as1Default:
  Tuple2as1With:
    added visit_newtype_struct

This commit fixes compilation error and actually fixes the issue as it was reported in serde-rs#2105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants