From 6f1a8c3115c8d2502178c25d610fbaee2e82c46b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 5 Jan 2024 18:12:20 -0800 Subject: [PATCH 1/3] Add FIXME to fix dead_code warning when using serde(remote) warning: field `0` is never read --> test_suite/tests/test_remote.rs:143:24 | 143 | struct PrimitivePubDef(u8); | --------------- ^^ | | | field in this struct | = note: `#[warn(dead_code)]` on by default help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 143 | struct PrimitivePubDef(()); | ~~ warning: field `0` is never read --> test_suite/tests/test_remote.rs:162:20 | 162 | struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit); | ----------- ^^ | | | field in this struct | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 162 | struct TuplePubDef((), #[serde(with = "UnitDef")] remote::Unit); | ~~ warning: field `0` is never read --> test_suite/tests/test_remote.rs:200:13 | 200 | Variant(u8), | ------- ^^ | | | field in this variant | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 200 | Variant(()), | ~~ error: field `0` is never read --> test_suite/tests/test_gen.rs:390:23 | 390 | struct StrDef<'a>(&'a str); | ------ ^^^^^^^ | | | field in this struct | note: the lint level is defined here --> test_suite/tests/test_gen.rs:5:9 | 5 | #![deny(warnings)] | ^^^^^^^^ = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]` help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 390 | struct StrDef<'a>(()); | ~~ --- test_suite/tests/test_gen.rs | 1 + test_suite/tests/test_remote.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/test_suite/tests/test_gen.rs b/test_suite/tests/test_gen.rs index 97b0a96e9..eca197cd3 100644 --- a/test_suite/tests/test_gen.rs +++ b/test_suite/tests/test_gen.rs @@ -387,6 +387,7 @@ fn test_gen() { #[derive(Serialize, Deserialize)] #[serde(remote = "Str")] + #[allow(dead_code)] // FIXME struct StrDef<'a>(&'a str); #[derive(Serialize, Deserialize)] diff --git a/test_suite/tests/test_remote.rs b/test_suite/tests/test_remote.rs index c1f152eb8..0c0827c9f 100644 --- a/test_suite/tests/test_remote.rs +++ b/test_suite/tests/test_remote.rs @@ -140,6 +140,7 @@ struct PrimitivePrivDef(#[serde(getter = "remote::PrimitivePriv::get")] u8); #[derive(Serialize, Deserialize)] #[serde(remote = "remote::PrimitivePub")] +#[allow(dead_code)] // FIXME struct PrimitivePubDef(u8); #[derive(Serialize, Deserialize)] @@ -159,6 +160,7 @@ struct TuplePrivDef( #[derive(Serialize, Deserialize)] #[serde(remote = "remote::TuplePub")] +#[allow(dead_code)] // FIXME struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit); #[derive(Serialize, Deserialize)] @@ -196,6 +198,7 @@ struct StructConcrete { #[derive(Serialize, Deserialize)] #[serde(remote = "remote::EnumGeneric")] +#[allow(dead_code)] // FIXME enum EnumConcrete { Variant(u8), } From 6502b3131697eff6420786ad71f87f29cfff3a13 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 5 Jan 2024 18:24:43 -0800 Subject: [PATCH 2/3] Fix new dead_code warning in tuple struct and tuple variant remote defs --- serde_derive/src/pretend.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/serde_derive/src/pretend.rs b/serde_derive/src/pretend.rs index 04868753b..2c9e77936 100644 --- a/serde_derive/src/pretend.rs +++ b/serde_derive/src/pretend.rs @@ -64,14 +64,14 @@ pub fn pretend_used(cont: &Container, is_packed: bool) -> TokenStream { fn pretend_fields_used(cont: &Container, is_packed: bool) -> TokenStream { match &cont.data { Data::Enum(variants) => pretend_fields_used_enum(cont, variants), - Data::Struct(Style::Struct, fields) => { + Data::Struct(Style::Struct | Style::Tuple | Style::Newtype, fields) => { if is_packed { pretend_fields_used_struct_packed(cont, fields) } else { pretend_fields_used_struct(cont, fields) } } - Data::Struct(_, _) => quote!(), + Data::Struct(Style::Unit, _) => quote!(), } } @@ -115,13 +115,13 @@ fn pretend_fields_used_enum(cont: &Container, variants: &[Variant]) -> TokenStre let patterns = variants .iter() .filter_map(|variant| match variant.style { - Style::Struct => { + Style::Struct | Style::Tuple | Style::Newtype => { let variant_ident = &variant.ident; let members = variant.fields.iter().map(|field| &field.member); let placeholders = (0usize..).map(|i| format_ident!("__v{}", i)); Some(quote!(#type_ident::#variant_ident { #(#members: #placeholders),* })) } - _ => None, + Style::Unit => None, }) .collect::>(); From 38d9e0b2091e9b6150486c2c37367819b86bcc39 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 5 Jan 2024 18:19:12 -0800 Subject: [PATCH 3/3] Revert "Add FIXME to fix dead_code warning when using serde(remote)" --- test_suite/tests/test_gen.rs | 1 - test_suite/tests/test_remote.rs | 3 --- 2 files changed, 4 deletions(-) diff --git a/test_suite/tests/test_gen.rs b/test_suite/tests/test_gen.rs index eca197cd3..97b0a96e9 100644 --- a/test_suite/tests/test_gen.rs +++ b/test_suite/tests/test_gen.rs @@ -387,7 +387,6 @@ fn test_gen() { #[derive(Serialize, Deserialize)] #[serde(remote = "Str")] - #[allow(dead_code)] // FIXME struct StrDef<'a>(&'a str); #[derive(Serialize, Deserialize)] diff --git a/test_suite/tests/test_remote.rs b/test_suite/tests/test_remote.rs index 0c0827c9f..c1f152eb8 100644 --- a/test_suite/tests/test_remote.rs +++ b/test_suite/tests/test_remote.rs @@ -140,7 +140,6 @@ struct PrimitivePrivDef(#[serde(getter = "remote::PrimitivePriv::get")] u8); #[derive(Serialize, Deserialize)] #[serde(remote = "remote::PrimitivePub")] -#[allow(dead_code)] // FIXME struct PrimitivePubDef(u8); #[derive(Serialize, Deserialize)] @@ -160,7 +159,6 @@ struct TuplePrivDef( #[derive(Serialize, Deserialize)] #[serde(remote = "remote::TuplePub")] -#[allow(dead_code)] // FIXME struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit); #[derive(Serialize, Deserialize)] @@ -198,7 +196,6 @@ struct StructConcrete { #[derive(Serialize, Deserialize)] #[serde(remote = "remote::EnumGeneric")] -#[allow(dead_code)] // FIXME enum EnumConcrete { Variant(u8), }