Files
serde/test_suite/tests/test_remote.rs
T
David Tolnay 6f1a8c3115 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>(());
        |                       ~~
2024-01-05 18:12:26 -08:00

252 lines
5.4 KiB
Rust

#![allow(clippy::redundant_field_names)]
use serde_derive::{Deserialize, Serialize};
mod remote {
pub struct Unit;
pub struct PrimitivePriv(u8);
pub struct PrimitivePub(pub u8);
pub struct NewtypePriv(Unit);
pub struct NewtypePub(pub Unit);
pub struct TuplePriv(u8, Unit);
pub struct TuplePub(pub u8, pub Unit);
pub struct StructPriv {
a: u8,
b: Unit,
}
pub struct StructPub {
pub a: u8,
pub b: Unit,
}
impl PrimitivePriv {
pub fn new(a: u8) -> Self {
PrimitivePriv(a)
}
pub fn get(&self) -> u8 {
self.0
}
}
impl NewtypePriv {
pub fn new(a: Unit) -> Self {
NewtypePriv(a)
}
pub fn get(&self) -> &Unit {
&self.0
}
}
impl TuplePriv {
pub fn new(a: u8, b: Unit) -> Self {
TuplePriv(a, b)
}
pub fn first(&self) -> u8 {
self.0
}
pub fn second(&self) -> &Unit {
&self.1
}
}
impl StructPriv {
pub fn new(a: u8, b: Unit) -> Self {
StructPriv { a: a, b: b }
}
pub fn a(&self) -> u8 {
self.a
}
pub fn b(&self) -> &Unit {
&self.b
}
}
pub struct StructGeneric<T> {
pub value: T,
}
impl<T> StructGeneric<T> {
#[allow(dead_code)]
pub fn get_value(&self) -> &T {
&self.value
}
}
pub enum EnumGeneric<T> {
Variant(T),
}
}
#[derive(Serialize, Deserialize)]
struct Test {
#[serde(with = "UnitDef")]
unit: remote::Unit,
#[serde(with = "PrimitivePrivDef")]
primitive_priv: remote::PrimitivePriv,
#[serde(with = "PrimitivePubDef")]
primitive_pub: remote::PrimitivePub,
#[serde(with = "NewtypePrivDef")]
newtype_priv: remote::NewtypePriv,
#[serde(with = "NewtypePubDef")]
newtype_pub: remote::NewtypePub,
#[serde(with = "TuplePrivDef")]
tuple_priv: remote::TuplePriv,
#[serde(with = "TuplePubDef")]
tuple_pub: remote::TuplePub,
#[serde(with = "StructPrivDef")]
struct_priv: remote::StructPriv,
#[serde(with = "StructPubDef")]
struct_pub: remote::StructPub,
#[serde(with = "StructConcrete")]
struct_concrete: remote::StructGeneric<u8>,
#[serde(with = "EnumConcrete")]
enum_concrete: remote::EnumGeneric<u8>,
#[serde(with = "ErrorKindDef")]
io_error_kind: ErrorKind,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::Unit")]
struct UnitDef;
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::PrimitivePriv")]
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)]
#[serde(remote = "remote::NewtypePriv")]
struct NewtypePrivDef(#[serde(getter = "remote::NewtypePriv::get", with = "UnitDef")] remote::Unit);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::NewtypePub")]
struct NewtypePubDef(#[serde(with = "UnitDef")] remote::Unit);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::TuplePriv")]
struct TuplePrivDef(
#[serde(getter = "remote::TuplePriv::first")] u8,
#[serde(getter = "remote::TuplePriv::second", with = "UnitDef")] remote::Unit,
);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::TuplePub")]
#[allow(dead_code)] // FIXME
struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructPriv")]
struct StructPrivDef {
#[serde(getter = "remote::StructPriv::a")]
a: u8,
#[serde(getter = "remote::StructPriv::b")]
#[serde(with = "UnitDef")]
b: remote::Unit,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructPub")]
struct StructPubDef {
a: u8,
#[serde(with = "UnitDef")]
b: remote::Unit,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructGeneric")]
struct StructGenericWithGetterDef<T> {
#[serde(getter = "remote::StructGeneric::get_value")]
value: T,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructGeneric<u8>")]
struct StructConcrete {
value: u8,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::EnumGeneric<u8>")]
#[allow(dead_code)] // FIXME
enum EnumConcrete {
Variant(u8),
}
#[derive(Debug)]
enum ErrorKind {
NotFound,
PermissionDenied,
#[allow(dead_code)]
ConnectionRefused,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "ErrorKind")]
#[non_exhaustive]
enum ErrorKindDef {
NotFound,
PermissionDenied,
// ...
}
impl From<PrimitivePrivDef> for remote::PrimitivePriv {
fn from(def: PrimitivePrivDef) -> Self {
remote::PrimitivePriv::new(def.0)
}
}
impl From<NewtypePrivDef> for remote::NewtypePriv {
fn from(def: NewtypePrivDef) -> Self {
remote::NewtypePriv::new(def.0)
}
}
impl From<TuplePrivDef> for remote::TuplePriv {
fn from(def: TuplePrivDef) -> Self {
remote::TuplePriv::new(def.0, def.1)
}
}
impl From<StructPrivDef> for remote::StructPriv {
fn from(def: StructPrivDef) -> Self {
remote::StructPriv::new(def.a, def.b)
}
}
impl<T> From<StructGenericWithGetterDef<T>> for remote::StructGeneric<T> {
fn from(def: StructGenericWithGetterDef<T>) -> Self {
remote::StructGeneric { value: def.value }
}
}