17e2e9c0cSopenharmony_ci// These just test that serde_derive is able to produce code that compiles
27e2e9c0cSopenharmony_ci// successfully when there are a variety of generics and non-(de)serializable
37e2e9c0cSopenharmony_ci// types involved.
47e2e9c0cSopenharmony_ci
57e2e9c0cSopenharmony_ci#![deny(warnings)]
67e2e9c0cSopenharmony_ci#![allow(
77e2e9c0cSopenharmony_ci    unknown_lints,
87e2e9c0cSopenharmony_ci    mixed_script_confusables,
97e2e9c0cSopenharmony_ci    clippy::derive_partial_eq_without_eq,
107e2e9c0cSopenharmony_ci    clippy::extra_unused_type_parameters,
117e2e9c0cSopenharmony_ci    clippy::items_after_statements,
127e2e9c0cSopenharmony_ci    clippy::missing_errors_doc,
137e2e9c0cSopenharmony_ci    clippy::missing_panics_doc,
147e2e9c0cSopenharmony_ci    clippy::must_use_candidate,
157e2e9c0cSopenharmony_ci    // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422
167e2e9c0cSopenharmony_ci    clippy::nonstandard_macro_braces,
177e2e9c0cSopenharmony_ci    clippy::ptr_arg,
187e2e9c0cSopenharmony_ci    clippy::too_many_lines,
197e2e9c0cSopenharmony_ci    clippy::trivially_copy_pass_by_ref,
207e2e9c0cSopenharmony_ci    clippy::type_repetition_in_bounds
217e2e9c0cSopenharmony_ci)]
227e2e9c0cSopenharmony_ci
237e2e9c0cSopenharmony_ciuse serde::de::{Deserialize, DeserializeOwned, Deserializer};
247e2e9c0cSopenharmony_ciuse serde::ser::{Serialize, Serializer};
257e2e9c0cSopenharmony_ciuse serde_derive::{Deserialize, Serialize};
267e2e9c0cSopenharmony_ciuse std::borrow::Cow;
277e2e9c0cSopenharmony_ciuse std::marker::PhantomData;
287e2e9c0cSopenharmony_ciuse std::option::Option as StdOption;
297e2e9c0cSopenharmony_ciuse std::result::Result as StdResult;
307e2e9c0cSopenharmony_ci
317e2e9c0cSopenharmony_ci// Try to trip up the generated code if it fails to use fully qualified paths.
327e2e9c0cSopenharmony_ci#[allow(dead_code)]
337e2e9c0cSopenharmony_cistruct Result;
347e2e9c0cSopenharmony_ci#[allow(dead_code)]
357e2e9c0cSopenharmony_cistruct Ok;
367e2e9c0cSopenharmony_ci#[allow(dead_code)]
377e2e9c0cSopenharmony_cistruct Err;
387e2e9c0cSopenharmony_ci#[allow(dead_code)]
397e2e9c0cSopenharmony_cistruct Option;
407e2e9c0cSopenharmony_ci#[allow(dead_code)]
417e2e9c0cSopenharmony_cistruct Some;
427e2e9c0cSopenharmony_ci#[allow(dead_code)]
437e2e9c0cSopenharmony_cistruct None;
447e2e9c0cSopenharmony_ci
457e2e9c0cSopenharmony_ci//////////////////////////////////////////////////////////////////////////
467e2e9c0cSopenharmony_ci
477e2e9c0cSopenharmony_ci#[test]
487e2e9c0cSopenharmony_cifn test_gen() {
497e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
507e2e9c0cSopenharmony_ci    struct With<T> {
517e2e9c0cSopenharmony_ci        t: T,
527e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x", deserialize_with = "de_x")]
537e2e9c0cSopenharmony_ci        x: X,
547e2e9c0cSopenharmony_ci    }
557e2e9c0cSopenharmony_ci    assert::<With<i32>>();
567e2e9c0cSopenharmony_ci
577e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
587e2e9c0cSopenharmony_ci    struct WithTogether<T> {
597e2e9c0cSopenharmony_ci        t: T,
607e2e9c0cSopenharmony_ci        #[serde(with = "both_x")]
617e2e9c0cSopenharmony_ci        x: X,
627e2e9c0cSopenharmony_ci    }
637e2e9c0cSopenharmony_ci    assert::<WithTogether<i32>>();
647e2e9c0cSopenharmony_ci
657e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
667e2e9c0cSopenharmony_ci    struct WithRef<'a, T: 'a> {
677e2e9c0cSopenharmony_ci        #[serde(skip_deserializing)]
687e2e9c0cSopenharmony_ci        t: StdOption<&'a T>,
697e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x", deserialize_with = "de_x")]
707e2e9c0cSopenharmony_ci        x: X,
717e2e9c0cSopenharmony_ci    }
727e2e9c0cSopenharmony_ci    assert::<WithRef<i32>>();
737e2e9c0cSopenharmony_ci
747e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
757e2e9c0cSopenharmony_ci    struct PhantomX {
767e2e9c0cSopenharmony_ci        x: PhantomData<X>,
777e2e9c0cSopenharmony_ci    }
787e2e9c0cSopenharmony_ci    assert::<PhantomX>();
797e2e9c0cSopenharmony_ci
807e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
817e2e9c0cSopenharmony_ci    struct PhantomT<T> {
827e2e9c0cSopenharmony_ci        t: PhantomData<T>,
837e2e9c0cSopenharmony_ci    }
847e2e9c0cSopenharmony_ci    assert::<PhantomT<X>>();
857e2e9c0cSopenharmony_ci
867e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
877e2e9c0cSopenharmony_ci    struct NoBounds<T> {
887e2e9c0cSopenharmony_ci        t: T,
897e2e9c0cSopenharmony_ci        option: StdOption<T>,
907e2e9c0cSopenharmony_ci        boxed: Box<T>,
917e2e9c0cSopenharmony_ci        option_boxed: StdOption<Box<T>>,
927e2e9c0cSopenharmony_ci    }
937e2e9c0cSopenharmony_ci    assert::<NoBounds<i32>>();
947e2e9c0cSopenharmony_ci
957e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
967e2e9c0cSopenharmony_ci    enum EnumWith<T> {
977e2e9c0cSopenharmony_ci        Unit,
987e2e9c0cSopenharmony_ci        Newtype(#[serde(serialize_with = "ser_x", deserialize_with = "de_x")] X),
997e2e9c0cSopenharmony_ci        Tuple(
1007e2e9c0cSopenharmony_ci            T,
1017e2e9c0cSopenharmony_ci            #[serde(serialize_with = "ser_x", deserialize_with = "de_x")] X,
1027e2e9c0cSopenharmony_ci        ),
1037e2e9c0cSopenharmony_ci        Struct {
1047e2e9c0cSopenharmony_ci            t: T,
1057e2e9c0cSopenharmony_ci            #[serde(serialize_with = "ser_x", deserialize_with = "de_x")]
1067e2e9c0cSopenharmony_ci            x: X,
1077e2e9c0cSopenharmony_ci        },
1087e2e9c0cSopenharmony_ci    }
1097e2e9c0cSopenharmony_ci    assert::<EnumWith<i32>>();
1107e2e9c0cSopenharmony_ci
1117e2e9c0cSopenharmony_ci    #[derive(Serialize)]
1127e2e9c0cSopenharmony_ci    struct MultipleRef<'a, 'b, 'c, T>
1137e2e9c0cSopenharmony_ci    where
1147e2e9c0cSopenharmony_ci        T: 'c,
1157e2e9c0cSopenharmony_ci        'c: 'b,
1167e2e9c0cSopenharmony_ci        'b: 'a,
1177e2e9c0cSopenharmony_ci    {
1187e2e9c0cSopenharmony_ci        t: T,
1197e2e9c0cSopenharmony_ci        rrrt: &'a &'b &'c T,
1207e2e9c0cSopenharmony_ci    }
1217e2e9c0cSopenharmony_ci    assert_ser::<MultipleRef<i32>>();
1227e2e9c0cSopenharmony_ci
1237e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
1247e2e9c0cSopenharmony_ci    struct Newtype(#[serde(serialize_with = "ser_x", deserialize_with = "de_x")] X);
1257e2e9c0cSopenharmony_ci    assert::<Newtype>();
1267e2e9c0cSopenharmony_ci
1277e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
1287e2e9c0cSopenharmony_ci    struct Tuple<T>(
1297e2e9c0cSopenharmony_ci        T,
1307e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x", deserialize_with = "de_x")] X,
1317e2e9c0cSopenharmony_ci    );
1327e2e9c0cSopenharmony_ci    assert::<Tuple<i32>>();
1337e2e9c0cSopenharmony_ci
1347e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
1357e2e9c0cSopenharmony_ci    enum TreeNode<D> {
1367e2e9c0cSopenharmony_ci        Split {
1377e2e9c0cSopenharmony_ci            left: Box<TreeNode<D>>,
1387e2e9c0cSopenharmony_ci            right: Box<TreeNode<D>>,
1397e2e9c0cSopenharmony_ci        },
1407e2e9c0cSopenharmony_ci        Leaf {
1417e2e9c0cSopenharmony_ci            data: D,
1427e2e9c0cSopenharmony_ci        },
1437e2e9c0cSopenharmony_ci    }
1447e2e9c0cSopenharmony_ci    assert::<TreeNode<i32>>();
1457e2e9c0cSopenharmony_ci
1467e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
1477e2e9c0cSopenharmony_ci    struct ListNode<D> {
1487e2e9c0cSopenharmony_ci        data: D,
1497e2e9c0cSopenharmony_ci        next: Box<ListNode<D>>,
1507e2e9c0cSopenharmony_ci    }
1517e2e9c0cSopenharmony_ci    assert::<ListNode<i32>>();
1527e2e9c0cSopenharmony_ci
1537e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
1547e2e9c0cSopenharmony_ci    struct RecursiveA {
1557e2e9c0cSopenharmony_ci        b: Box<RecursiveB>,
1567e2e9c0cSopenharmony_ci    }
1577e2e9c0cSopenharmony_ci    assert::<RecursiveA>();
1587e2e9c0cSopenharmony_ci
1597e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
1607e2e9c0cSopenharmony_ci    enum RecursiveB {
1617e2e9c0cSopenharmony_ci        A(RecursiveA),
1627e2e9c0cSopenharmony_ci    }
1637e2e9c0cSopenharmony_ci    assert::<RecursiveB>();
1647e2e9c0cSopenharmony_ci
1657e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
1667e2e9c0cSopenharmony_ci    struct RecursiveGenericA<T> {
1677e2e9c0cSopenharmony_ci        t: T,
1687e2e9c0cSopenharmony_ci        b: Box<RecursiveGenericB<T>>,
1697e2e9c0cSopenharmony_ci    }
1707e2e9c0cSopenharmony_ci    assert::<RecursiveGenericA<i32>>();
1717e2e9c0cSopenharmony_ci
1727e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
1737e2e9c0cSopenharmony_ci    enum RecursiveGenericB<T> {
1747e2e9c0cSopenharmony_ci        T(T),
1757e2e9c0cSopenharmony_ci        A(RecursiveGenericA<T>),
1767e2e9c0cSopenharmony_ci    }
1777e2e9c0cSopenharmony_ci    assert::<RecursiveGenericB<i32>>();
1787e2e9c0cSopenharmony_ci
1797e2e9c0cSopenharmony_ci    #[derive(Serialize)]
1807e2e9c0cSopenharmony_ci    struct OptionStatic<'a> {
1817e2e9c0cSopenharmony_ci        a: StdOption<&'a str>,
1827e2e9c0cSopenharmony_ci        b: StdOption<&'static str>,
1837e2e9c0cSopenharmony_ci    }
1847e2e9c0cSopenharmony_ci    assert_ser::<OptionStatic>();
1857e2e9c0cSopenharmony_ci
1867e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
1877e2e9c0cSopenharmony_ci    #[serde(bound = "D: SerializeWith + DeserializeWith")]
1887e2e9c0cSopenharmony_ci    struct WithTraits1<D, E> {
1897e2e9c0cSopenharmony_ci        #[serde(
1907e2e9c0cSopenharmony_ci            serialize_with = "SerializeWith::serialize_with",
1917e2e9c0cSopenharmony_ci            deserialize_with = "DeserializeWith::deserialize_with"
1927e2e9c0cSopenharmony_ci        )]
1937e2e9c0cSopenharmony_ci        d: D,
1947e2e9c0cSopenharmony_ci        #[serde(
1957e2e9c0cSopenharmony_ci            serialize_with = "SerializeWith::serialize_with",
1967e2e9c0cSopenharmony_ci            deserialize_with = "DeserializeWith::deserialize_with",
1977e2e9c0cSopenharmony_ci            bound = "E: SerializeWith + DeserializeWith"
1987e2e9c0cSopenharmony_ci        )]
1997e2e9c0cSopenharmony_ci        e: E,
2007e2e9c0cSopenharmony_ci    }
2017e2e9c0cSopenharmony_ci    assert::<WithTraits1<X, X>>();
2027e2e9c0cSopenharmony_ci
2037e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2047e2e9c0cSopenharmony_ci    #[serde(bound(serialize = "D: SerializeWith", deserialize = "D: DeserializeWith"))]
2057e2e9c0cSopenharmony_ci    struct WithTraits2<D, E> {
2067e2e9c0cSopenharmony_ci        #[serde(
2077e2e9c0cSopenharmony_ci            serialize_with = "SerializeWith::serialize_with",
2087e2e9c0cSopenharmony_ci            deserialize_with = "DeserializeWith::deserialize_with"
2097e2e9c0cSopenharmony_ci        )]
2107e2e9c0cSopenharmony_ci        d: D,
2117e2e9c0cSopenharmony_ci        #[serde(
2127e2e9c0cSopenharmony_ci            serialize_with = "SerializeWith::serialize_with",
2137e2e9c0cSopenharmony_ci            bound(serialize = "E: SerializeWith")
2147e2e9c0cSopenharmony_ci        )]
2157e2e9c0cSopenharmony_ci        #[serde(
2167e2e9c0cSopenharmony_ci            deserialize_with = "DeserializeWith::deserialize_with",
2177e2e9c0cSopenharmony_ci            bound(deserialize = "E: DeserializeWith")
2187e2e9c0cSopenharmony_ci        )]
2197e2e9c0cSopenharmony_ci        e: E,
2207e2e9c0cSopenharmony_ci    }
2217e2e9c0cSopenharmony_ci    assert::<WithTraits2<X, X>>();
2227e2e9c0cSopenharmony_ci
2237e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2247e2e9c0cSopenharmony_ci    #[serde(bound = "D: SerializeWith + DeserializeWith")]
2257e2e9c0cSopenharmony_ci    enum VariantWithTraits1<D, E> {
2267e2e9c0cSopenharmony_ci        #[serde(
2277e2e9c0cSopenharmony_ci            serialize_with = "SerializeWith::serialize_with",
2287e2e9c0cSopenharmony_ci            deserialize_with = "DeserializeWith::deserialize_with"
2297e2e9c0cSopenharmony_ci        )]
2307e2e9c0cSopenharmony_ci        D(D),
2317e2e9c0cSopenharmony_ci        #[serde(
2327e2e9c0cSopenharmony_ci            serialize_with = "SerializeWith::serialize_with",
2337e2e9c0cSopenharmony_ci            deserialize_with = "DeserializeWith::deserialize_with",
2347e2e9c0cSopenharmony_ci            bound = "E: SerializeWith + DeserializeWith"
2357e2e9c0cSopenharmony_ci        )]
2367e2e9c0cSopenharmony_ci        E(E),
2377e2e9c0cSopenharmony_ci    }
2387e2e9c0cSopenharmony_ci    assert::<VariantWithTraits1<X, X>>();
2397e2e9c0cSopenharmony_ci
2407e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2417e2e9c0cSopenharmony_ci    #[serde(bound(serialize = "D: SerializeWith", deserialize = "D: DeserializeWith"))]
2427e2e9c0cSopenharmony_ci    enum VariantWithTraits2<D, E> {
2437e2e9c0cSopenharmony_ci        #[serde(
2447e2e9c0cSopenharmony_ci            serialize_with = "SerializeWith::serialize_with",
2457e2e9c0cSopenharmony_ci            deserialize_with = "DeserializeWith::deserialize_with"
2467e2e9c0cSopenharmony_ci        )]
2477e2e9c0cSopenharmony_ci        D(D),
2487e2e9c0cSopenharmony_ci        #[serde(
2497e2e9c0cSopenharmony_ci            serialize_with = "SerializeWith::serialize_with",
2507e2e9c0cSopenharmony_ci            bound(serialize = "E: SerializeWith")
2517e2e9c0cSopenharmony_ci        )]
2527e2e9c0cSopenharmony_ci        #[serde(
2537e2e9c0cSopenharmony_ci            deserialize_with = "DeserializeWith::deserialize_with",
2547e2e9c0cSopenharmony_ci            bound(deserialize = "E: DeserializeWith")
2557e2e9c0cSopenharmony_ci        )]
2567e2e9c0cSopenharmony_ci        E(E),
2577e2e9c0cSopenharmony_ci    }
2587e2e9c0cSopenharmony_ci    assert::<VariantWithTraits2<X, X>>();
2597e2e9c0cSopenharmony_ci
2607e2e9c0cSopenharmony_ci    type PhantomDataAlias<T> = PhantomData<T>;
2617e2e9c0cSopenharmony_ci
2627e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2637e2e9c0cSopenharmony_ci    #[serde(bound = "")]
2647e2e9c0cSopenharmony_ci    struct PhantomDataWrapper<T> {
2657e2e9c0cSopenharmony_ci        #[serde(default)]
2667e2e9c0cSopenharmony_ci        field: PhantomDataAlias<T>,
2677e2e9c0cSopenharmony_ci    }
2687e2e9c0cSopenharmony_ci    assert::<PhantomDataWrapper<X>>();
2697e2e9c0cSopenharmony_ci
2707e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2717e2e9c0cSopenharmony_ci    struct CowStr<'a>(Cow<'a, str>);
2727e2e9c0cSopenharmony_ci    assert::<CowStr>();
2737e2e9c0cSopenharmony_ci
2747e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2757e2e9c0cSopenharmony_ci    #[serde(bound(deserialize = "T::Owned: DeserializeOwned"))]
2767e2e9c0cSopenharmony_ci    struct CowT<'a, T: ?Sized + 'a + ToOwned>(Cow<'a, T>);
2777e2e9c0cSopenharmony_ci    assert::<CowT<str>>();
2787e2e9c0cSopenharmony_ci
2797e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2807e2e9c0cSopenharmony_ci    struct EmptyStruct {}
2817e2e9c0cSopenharmony_ci    assert::<EmptyStruct>();
2827e2e9c0cSopenharmony_ci
2837e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2847e2e9c0cSopenharmony_ci    enum EmptyEnumVariant {
2857e2e9c0cSopenharmony_ci        EmptyStruct {},
2867e2e9c0cSopenharmony_ci    }
2877e2e9c0cSopenharmony_ci    assert::<EmptyEnumVariant>();
2887e2e9c0cSopenharmony_ci
2897e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2907e2e9c0cSopenharmony_ci    struct NonAsciiIdents {
2917e2e9c0cSopenharmony_ci        σ: f64,
2927e2e9c0cSopenharmony_ci    }
2937e2e9c0cSopenharmony_ci
2947e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2957e2e9c0cSopenharmony_ci    struct EmptyBraced {}
2967e2e9c0cSopenharmony_ci
2977e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
2987e2e9c0cSopenharmony_ci    #[serde(deny_unknown_fields)]
2997e2e9c0cSopenharmony_ci    struct EmptyBracedDenyUnknown {}
3007e2e9c0cSopenharmony_ci
3017e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3027e2e9c0cSopenharmony_ci    struct BracedSkipAll {
3037e2e9c0cSopenharmony_ci        #[serde(skip_deserializing)]
3047e2e9c0cSopenharmony_ci        f: u8,
3057e2e9c0cSopenharmony_ci    }
3067e2e9c0cSopenharmony_ci
3077e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3087e2e9c0cSopenharmony_ci    #[serde(deny_unknown_fields)]
3097e2e9c0cSopenharmony_ci    struct BracedSkipAllDenyUnknown {
3107e2e9c0cSopenharmony_ci        #[serde(skip_deserializing)]
3117e2e9c0cSopenharmony_ci        f: u8,
3127e2e9c0cSopenharmony_ci    }
3137e2e9c0cSopenharmony_ci
3147e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3157e2e9c0cSopenharmony_ci    struct EmptyTuple();
3167e2e9c0cSopenharmony_ci
3177e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3187e2e9c0cSopenharmony_ci    #[serde(deny_unknown_fields)]
3197e2e9c0cSopenharmony_ci    struct EmptyTupleDenyUnknown();
3207e2e9c0cSopenharmony_ci
3217e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3227e2e9c0cSopenharmony_ci    struct TupleSkipAll(#[serde(skip_deserializing)] u8);
3237e2e9c0cSopenharmony_ci
3247e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3257e2e9c0cSopenharmony_ci    #[serde(deny_unknown_fields)]
3267e2e9c0cSopenharmony_ci    struct TupleSkipAllDenyUnknown(#[serde(skip_deserializing)] u8);
3277e2e9c0cSopenharmony_ci
3287e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3297e2e9c0cSopenharmony_ci    enum EmptyEnum {}
3307e2e9c0cSopenharmony_ci
3317e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3327e2e9c0cSopenharmony_ci    #[serde(deny_unknown_fields)]
3337e2e9c0cSopenharmony_ci    enum EmptyEnumDenyUnknown {}
3347e2e9c0cSopenharmony_ci
3357e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3367e2e9c0cSopenharmony_ci    enum EnumSkipAll {
3377e2e9c0cSopenharmony_ci        #[serde(skip_deserializing)]
3387e2e9c0cSopenharmony_ci        #[allow(dead_code)]
3397e2e9c0cSopenharmony_ci        Variant,
3407e2e9c0cSopenharmony_ci    }
3417e2e9c0cSopenharmony_ci
3427e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3437e2e9c0cSopenharmony_ci    enum EmptyVariants {
3447e2e9c0cSopenharmony_ci        Braced {},
3457e2e9c0cSopenharmony_ci        Tuple(),
3467e2e9c0cSopenharmony_ci        BracedSkip {
3477e2e9c0cSopenharmony_ci            #[serde(skip_deserializing)]
3487e2e9c0cSopenharmony_ci            f: u8,
3497e2e9c0cSopenharmony_ci        },
3507e2e9c0cSopenharmony_ci        TupleSkip(#[serde(skip_deserializing)] u8),
3517e2e9c0cSopenharmony_ci    }
3527e2e9c0cSopenharmony_ci
3537e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3547e2e9c0cSopenharmony_ci    #[serde(deny_unknown_fields)]
3557e2e9c0cSopenharmony_ci    enum EmptyVariantsDenyUnknown {
3567e2e9c0cSopenharmony_ci        Braced {},
3577e2e9c0cSopenharmony_ci        Tuple(),
3587e2e9c0cSopenharmony_ci        BracedSkip {
3597e2e9c0cSopenharmony_ci            #[serde(skip_deserializing)]
3607e2e9c0cSopenharmony_ci            f: u8,
3617e2e9c0cSopenharmony_ci        },
3627e2e9c0cSopenharmony_ci        TupleSkip(#[serde(skip_deserializing)] u8),
3637e2e9c0cSopenharmony_ci    }
3647e2e9c0cSopenharmony_ci
3657e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3667e2e9c0cSopenharmony_ci    #[serde(deny_unknown_fields)]
3677e2e9c0cSopenharmony_ci    struct UnitDenyUnknown;
3687e2e9c0cSopenharmony_ci
3697e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3707e2e9c0cSopenharmony_ci    struct EmptyArray {
3717e2e9c0cSopenharmony_ci        empty: [X; 0],
3727e2e9c0cSopenharmony_ci    }
3737e2e9c0cSopenharmony_ci
3747e2e9c0cSopenharmony_ci    enum Or<A, B> {
3757e2e9c0cSopenharmony_ci        A(A),
3767e2e9c0cSopenharmony_ci        B(B),
3777e2e9c0cSopenharmony_ci    }
3787e2e9c0cSopenharmony_ci
3797e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3807e2e9c0cSopenharmony_ci    #[serde(untagged, remote = "Or")]
3817e2e9c0cSopenharmony_ci    enum OrDef<A, B> {
3827e2e9c0cSopenharmony_ci        A(A),
3837e2e9c0cSopenharmony_ci        B(B),
3847e2e9c0cSopenharmony_ci    }
3857e2e9c0cSopenharmony_ci
3867e2e9c0cSopenharmony_ci    struct Str<'a>(&'a str);
3877e2e9c0cSopenharmony_ci
3887e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3897e2e9c0cSopenharmony_ci    #[serde(remote = "Str")]
3907e2e9c0cSopenharmony_ci    struct StrDef<'a>(&'a str);
3917e2e9c0cSopenharmony_ci
3927e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
3937e2e9c0cSopenharmony_ci    struct Remote<'a> {
3947e2e9c0cSopenharmony_ci        #[serde(with = "OrDef")]
3957e2e9c0cSopenharmony_ci        or: Or<u8, bool>,
3967e2e9c0cSopenharmony_ci        #[serde(borrow, with = "StrDef")]
3977e2e9c0cSopenharmony_ci        s: Str<'a>,
3987e2e9c0cSopenharmony_ci    }
3997e2e9c0cSopenharmony_ci
4007e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
4017e2e9c0cSopenharmony_ci    enum BorrowVariant<'a> {
4027e2e9c0cSopenharmony_ci        #[serde(borrow, with = "StrDef")]
4037e2e9c0cSopenharmony_ci        S(Str<'a>),
4047e2e9c0cSopenharmony_ci    }
4057e2e9c0cSopenharmony_ci
4067e2e9c0cSopenharmony_ci    mod vis {
4077e2e9c0cSopenharmony_ci        use serde_derive::{Deserialize, Serialize};
4087e2e9c0cSopenharmony_ci
4097e2e9c0cSopenharmony_ci        pub struct S;
4107e2e9c0cSopenharmony_ci
4117e2e9c0cSopenharmony_ci        #[derive(Serialize, Deserialize)]
4127e2e9c0cSopenharmony_ci        #[serde(remote = "S")]
4137e2e9c0cSopenharmony_ci        pub struct SDef;
4147e2e9c0cSopenharmony_ci    }
4157e2e9c0cSopenharmony_ci
4167e2e9c0cSopenharmony_ci    // This would not work if SDef::serialize / deserialize are private.
4177e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
4187e2e9c0cSopenharmony_ci    struct RemoteVisibility {
4197e2e9c0cSopenharmony_ci        #[serde(with = "vis::SDef")]
4207e2e9c0cSopenharmony_ci        s: vis::S,
4217e2e9c0cSopenharmony_ci    }
4227e2e9c0cSopenharmony_ci
4237e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
4247e2e9c0cSopenharmony_ci    #[serde(remote = "Self")]
4257e2e9c0cSopenharmony_ci    struct RemoteSelf;
4267e2e9c0cSopenharmony_ci
4277e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
4287e2e9c0cSopenharmony_ci    enum ExternallyTaggedVariantWith {
4297e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x")]
4307e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "de_x")]
4317e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4327e2e9c0cSopenharmony_ci        Newtype(X),
4337e2e9c0cSopenharmony_ci
4347e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_other_variant")]
4357e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_other_variant")]
4367e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4377e2e9c0cSopenharmony_ci        Tuple(String, u8),
4387e2e9c0cSopenharmony_ci
4397e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x")]
4407e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "de_x")]
4417e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4427e2e9c0cSopenharmony_ci        Struct1 { x: X },
4437e2e9c0cSopenharmony_ci
4447e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_other_variant")]
4457e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_other_variant")]
4467e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4477e2e9c0cSopenharmony_ci        Struct { f1: String, f2: u8 },
4487e2e9c0cSopenharmony_ci
4497e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_unit_variant")]
4507e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_unit_variant")]
4517e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4527e2e9c0cSopenharmony_ci        Unit,
4537e2e9c0cSopenharmony_ci    }
4547e2e9c0cSopenharmony_ci    assert_ser::<ExternallyTaggedVariantWith>();
4557e2e9c0cSopenharmony_ci
4567e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
4577e2e9c0cSopenharmony_ci    #[serde(tag = "t")]
4587e2e9c0cSopenharmony_ci    enum InternallyTaggedVariantWith {
4597e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x")]
4607e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "de_x")]
4617e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4627e2e9c0cSopenharmony_ci        Newtype(X),
4637e2e9c0cSopenharmony_ci
4647e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x")]
4657e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "de_x")]
4667e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4677e2e9c0cSopenharmony_ci        Struct1 { x: X },
4687e2e9c0cSopenharmony_ci
4697e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_other_variant")]
4707e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_other_variant")]
4717e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4727e2e9c0cSopenharmony_ci        Struct { f1: String, f2: u8 },
4737e2e9c0cSopenharmony_ci
4747e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_unit_variant")]
4757e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_unit_variant")]
4767e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4777e2e9c0cSopenharmony_ci        Unit,
4787e2e9c0cSopenharmony_ci    }
4797e2e9c0cSopenharmony_ci    assert_ser::<InternallyTaggedVariantWith>();
4807e2e9c0cSopenharmony_ci
4817e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
4827e2e9c0cSopenharmony_ci    #[serde(tag = "t", content = "c")]
4837e2e9c0cSopenharmony_ci    enum AdjacentlyTaggedVariantWith {
4847e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x")]
4857e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "de_x")]
4867e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4877e2e9c0cSopenharmony_ci        Newtype(X),
4887e2e9c0cSopenharmony_ci
4897e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_other_variant")]
4907e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_other_variant")]
4917e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4927e2e9c0cSopenharmony_ci        Tuple(String, u8),
4937e2e9c0cSopenharmony_ci
4947e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x")]
4957e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "de_x")]
4967e2e9c0cSopenharmony_ci        #[allow(dead_code)]
4977e2e9c0cSopenharmony_ci        Struct1 { x: X },
4987e2e9c0cSopenharmony_ci
4997e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_other_variant")]
5007e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_other_variant")]
5017e2e9c0cSopenharmony_ci        #[allow(dead_code)]
5027e2e9c0cSopenharmony_ci        Struct { f1: String, f2: u8 },
5037e2e9c0cSopenharmony_ci
5047e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_unit_variant")]
5057e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_unit_variant")]
5067e2e9c0cSopenharmony_ci        #[allow(dead_code)]
5077e2e9c0cSopenharmony_ci        Unit,
5087e2e9c0cSopenharmony_ci    }
5097e2e9c0cSopenharmony_ci    assert_ser::<AdjacentlyTaggedVariantWith>();
5107e2e9c0cSopenharmony_ci
5117e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
5127e2e9c0cSopenharmony_ci    #[serde(untagged)]
5137e2e9c0cSopenharmony_ci    enum UntaggedVariantWith {
5147e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x")]
5157e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "de_x")]
5167e2e9c0cSopenharmony_ci        #[allow(dead_code)]
5177e2e9c0cSopenharmony_ci        Newtype(X),
5187e2e9c0cSopenharmony_ci
5197e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_other_variant")]
5207e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_other_variant")]
5217e2e9c0cSopenharmony_ci        #[allow(dead_code)]
5227e2e9c0cSopenharmony_ci        Tuple(String, u8),
5237e2e9c0cSopenharmony_ci
5247e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x")]
5257e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "de_x")]
5267e2e9c0cSopenharmony_ci        #[allow(dead_code)]
5277e2e9c0cSopenharmony_ci        Struct1 { x: X },
5287e2e9c0cSopenharmony_ci
5297e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_other_variant")]
5307e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_other_variant")]
5317e2e9c0cSopenharmony_ci        #[allow(dead_code)]
5327e2e9c0cSopenharmony_ci        Struct { f1: String, f2: u8 },
5337e2e9c0cSopenharmony_ci
5347e2e9c0cSopenharmony_ci        #[serde(serialize_with = "serialize_some_unit_variant")]
5357e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "deserialize_some_unit_variant")]
5367e2e9c0cSopenharmony_ci        #[allow(dead_code)]
5377e2e9c0cSopenharmony_ci        Unit,
5387e2e9c0cSopenharmony_ci    }
5397e2e9c0cSopenharmony_ci    assert_ser::<UntaggedVariantWith>();
5407e2e9c0cSopenharmony_ci
5417e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
5427e2e9c0cSopenharmony_ci    struct FlattenWith {
5437e2e9c0cSopenharmony_ci        #[serde(flatten, serialize_with = "ser_x", deserialize_with = "de_x")]
5447e2e9c0cSopenharmony_ci        x: X,
5457e2e9c0cSopenharmony_ci    }
5467e2e9c0cSopenharmony_ci    assert::<FlattenWith>();
5477e2e9c0cSopenharmony_ci
5487e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
5497e2e9c0cSopenharmony_ci    #[serde(deny_unknown_fields)]
5507e2e9c0cSopenharmony_ci    struct FlattenDenyUnknown<T> {
5517e2e9c0cSopenharmony_ci        #[serde(flatten)]
5527e2e9c0cSopenharmony_ci        t: T,
5537e2e9c0cSopenharmony_ci    }
5547e2e9c0cSopenharmony_ci
5557e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
5567e2e9c0cSopenharmony_ci    struct StaticStrStruct<'a> {
5577e2e9c0cSopenharmony_ci        a: &'a str,
5587e2e9c0cSopenharmony_ci        b: &'static str,
5597e2e9c0cSopenharmony_ci    }
5607e2e9c0cSopenharmony_ci
5617e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
5627e2e9c0cSopenharmony_ci    struct StaticStrTupleStruct<'a>(&'a str, &'static str);
5637e2e9c0cSopenharmony_ci
5647e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
5657e2e9c0cSopenharmony_ci    struct StaticStrNewtypeStruct(&'static str);
5667e2e9c0cSopenharmony_ci
5677e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
5687e2e9c0cSopenharmony_ci    enum StaticStrEnum<'a> {
5697e2e9c0cSopenharmony_ci        Struct { a: &'a str, b: &'static str },
5707e2e9c0cSopenharmony_ci        Tuple(&'a str, &'static str),
5717e2e9c0cSopenharmony_ci        Newtype(&'static str),
5727e2e9c0cSopenharmony_ci    }
5737e2e9c0cSopenharmony_ci
5747e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
5757e2e9c0cSopenharmony_ci    struct SkippedStaticStr {
5767e2e9c0cSopenharmony_ci        #[serde(skip_deserializing)]
5777e2e9c0cSopenharmony_ci        skipped: &'static str,
5787e2e9c0cSopenharmony_ci        other: isize,
5797e2e9c0cSopenharmony_ci    }
5807e2e9c0cSopenharmony_ci    assert::<SkippedStaticStr>();
5817e2e9c0cSopenharmony_ci
5827e2e9c0cSopenharmony_ci    macro_rules! T {
5837e2e9c0cSopenharmony_ci        () => {
5847e2e9c0cSopenharmony_ci            ()
5857e2e9c0cSopenharmony_ci        };
5867e2e9c0cSopenharmony_ci    }
5877e2e9c0cSopenharmony_ci
5887e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
5897e2e9c0cSopenharmony_ci    struct TypeMacro<T> {
5907e2e9c0cSopenharmony_ci        mac: T!(),
5917e2e9c0cSopenharmony_ci        marker: PhantomData<T>,
5927e2e9c0cSopenharmony_ci    }
5937e2e9c0cSopenharmony_ci    assert::<TypeMacro<X>>();
5947e2e9c0cSopenharmony_ci
5957e2e9c0cSopenharmony_ci    #[derive(Serialize)]
5967e2e9c0cSopenharmony_ci    struct BigArray {
5977e2e9c0cSopenharmony_ci        #[serde(serialize_with = "<[_]>::serialize")]
5987e2e9c0cSopenharmony_ci        array: [u8; 256],
5997e2e9c0cSopenharmony_ci    }
6007e2e9c0cSopenharmony_ci    assert_ser::<BigArray>();
6017e2e9c0cSopenharmony_ci
6027e2e9c0cSopenharmony_ci    trait AssocSerde {
6037e2e9c0cSopenharmony_ci        type Assoc;
6047e2e9c0cSopenharmony_ci    }
6057e2e9c0cSopenharmony_ci
6067e2e9c0cSopenharmony_ci    struct NoSerdeImpl;
6077e2e9c0cSopenharmony_ci    impl AssocSerde for NoSerdeImpl {
6087e2e9c0cSopenharmony_ci        type Assoc = u32;
6097e2e9c0cSopenharmony_ci    }
6107e2e9c0cSopenharmony_ci
6117e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
6127e2e9c0cSopenharmony_ci    struct AssocDerive<T: AssocSerde> {
6137e2e9c0cSopenharmony_ci        assoc: T::Assoc,
6147e2e9c0cSopenharmony_ci    }
6157e2e9c0cSopenharmony_ci
6167e2e9c0cSopenharmony_ci    assert::<AssocDerive<NoSerdeImpl>>();
6177e2e9c0cSopenharmony_ci
6187e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
6197e2e9c0cSopenharmony_ci    struct AssocDeriveMulti<S, T: AssocSerde> {
6207e2e9c0cSopenharmony_ci        s: S,
6217e2e9c0cSopenharmony_ci        assoc: T::Assoc,
6227e2e9c0cSopenharmony_ci    }
6237e2e9c0cSopenharmony_ci
6247e2e9c0cSopenharmony_ci    assert::<AssocDeriveMulti<i32, NoSerdeImpl>>();
6257e2e9c0cSopenharmony_ci
6267e2e9c0cSopenharmony_ci    #[derive(Serialize)]
6277e2e9c0cSopenharmony_ci    #[serde(tag = "t", content = "c")]
6287e2e9c0cSopenharmony_ci    enum EmptyAdjacentlyTagged {
6297e2e9c0cSopenharmony_ci        #[allow(dead_code)]
6307e2e9c0cSopenharmony_ci        Struct {},
6317e2e9c0cSopenharmony_ci        #[allow(dead_code)]
6327e2e9c0cSopenharmony_ci        Tuple(),
6337e2e9c0cSopenharmony_ci    }
6347e2e9c0cSopenharmony_ci
6357e2e9c0cSopenharmony_ci    assert_ser::<EmptyAdjacentlyTagged>();
6367e2e9c0cSopenharmony_ci
6377e2e9c0cSopenharmony_ci    mod restricted {
6387e2e9c0cSopenharmony_ci        mod inner {
6397e2e9c0cSopenharmony_ci            use serde_derive::{Deserialize, Serialize};
6407e2e9c0cSopenharmony_ci
6417e2e9c0cSopenharmony_ci            #[derive(Serialize, Deserialize)]
6427e2e9c0cSopenharmony_ci            struct Restricted {
6437e2e9c0cSopenharmony_ci                pub(super) a: usize,
6447e2e9c0cSopenharmony_ci                pub(in super::inner) b: usize,
6457e2e9c0cSopenharmony_ci            }
6467e2e9c0cSopenharmony_ci        }
6477e2e9c0cSopenharmony_ci    }
6487e2e9c0cSopenharmony_ci
6497e2e9c0cSopenharmony_ci    #[derive(Deserialize)]
6507e2e9c0cSopenharmony_ci    #[serde(tag = "t", content = "c")]
6517e2e9c0cSopenharmony_ci    enum AdjacentlyTaggedVoid {}
6527e2e9c0cSopenharmony_ci
6537e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
6547e2e9c0cSopenharmony_ci    enum SkippedVariant<T> {
6557e2e9c0cSopenharmony_ci        #[serde(skip)]
6567e2e9c0cSopenharmony_ci        #[allow(dead_code)]
6577e2e9c0cSopenharmony_ci        T(T),
6587e2e9c0cSopenharmony_ci        Unit,
6597e2e9c0cSopenharmony_ci    }
6607e2e9c0cSopenharmony_ci
6617e2e9c0cSopenharmony_ci    assert::<SkippedVariant<X>>();
6627e2e9c0cSopenharmony_ci
6637e2e9c0cSopenharmony_ci    #[derive(Deserialize)]
6647e2e9c0cSopenharmony_ci    struct ImplicitlyBorrowedOption<'a> {
6657e2e9c0cSopenharmony_ci        #[allow(dead_code)]
6667e2e9c0cSopenharmony_ci        option: std::option::Option<&'a str>,
6677e2e9c0cSopenharmony_ci    }
6687e2e9c0cSopenharmony_ci
6697e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
6707e2e9c0cSopenharmony_ci    #[serde(untagged)]
6717e2e9c0cSopenharmony_ci    enum UntaggedNewtypeVariantWith {
6727e2e9c0cSopenharmony_ci        Newtype(
6737e2e9c0cSopenharmony_ci            #[serde(serialize_with = "ser_x")]
6747e2e9c0cSopenharmony_ci            #[serde(deserialize_with = "de_x")]
6757e2e9c0cSopenharmony_ci            X,
6767e2e9c0cSopenharmony_ci        ),
6777e2e9c0cSopenharmony_ci    }
6787e2e9c0cSopenharmony_ci
6797e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
6807e2e9c0cSopenharmony_ci    #[serde(transparent)]
6817e2e9c0cSopenharmony_ci    struct TransparentWith {
6827e2e9c0cSopenharmony_ci        #[serde(serialize_with = "ser_x")]
6837e2e9c0cSopenharmony_ci        #[serde(deserialize_with = "de_x")]
6847e2e9c0cSopenharmony_ci        x: X,
6857e2e9c0cSopenharmony_ci    }
6867e2e9c0cSopenharmony_ci
6877e2e9c0cSopenharmony_ci    #[derive(Deserialize)]
6887e2e9c0cSopenharmony_ci    #[serde(untagged)]
6897e2e9c0cSopenharmony_ci    pub enum UntaggedWithBorrow<'a> {
6907e2e9c0cSopenharmony_ci        Single(#[serde(borrow)] RelObject<'a>),
6917e2e9c0cSopenharmony_ci        Many(#[serde(borrow)] Vec<RelObject<'a>>),
6927e2e9c0cSopenharmony_ci    }
6937e2e9c0cSopenharmony_ci
6947e2e9c0cSopenharmony_ci    #[derive(Deserialize)]
6957e2e9c0cSopenharmony_ci    struct RelObject<'a> {
6967e2e9c0cSopenharmony_ci        #[allow(dead_code)]
6977e2e9c0cSopenharmony_ci        ty: &'a str,
6987e2e9c0cSopenharmony_ci        #[allow(dead_code)]
6997e2e9c0cSopenharmony_ci        id: String,
7007e2e9c0cSopenharmony_ci    }
7017e2e9c0cSopenharmony_ci
7027e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
7037e2e9c0cSopenharmony_ci    struct FlattenSkipSerializing<T> {
7047e2e9c0cSopenharmony_ci        #[serde(flatten, skip_serializing)]
7057e2e9c0cSopenharmony_ci        #[allow(dead_code)]
7067e2e9c0cSopenharmony_ci        flat: T,
7077e2e9c0cSopenharmony_ci    }
7087e2e9c0cSopenharmony_ci
7097e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
7107e2e9c0cSopenharmony_ci    struct FlattenSkipSerializingIf<T> {
7117e2e9c0cSopenharmony_ci        #[serde(flatten, skip_serializing_if = "StdOption::is_none")]
7127e2e9c0cSopenharmony_ci        flat: StdOption<T>,
7137e2e9c0cSopenharmony_ci    }
7147e2e9c0cSopenharmony_ci
7157e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
7167e2e9c0cSopenharmony_ci    struct FlattenSkipDeserializing<T> {
7177e2e9c0cSopenharmony_ci        #[serde(flatten, skip_deserializing)]
7187e2e9c0cSopenharmony_ci        flat: T,
7197e2e9c0cSopenharmony_ci    }
7207e2e9c0cSopenharmony_ci
7217e2e9c0cSopenharmony_ci    // https://github.com/serde-rs/serde/issues/1804
7227e2e9c0cSopenharmony_ci    #[derive(Serialize, Deserialize)]
7237e2e9c0cSopenharmony_ci    enum Message {
7247e2e9c0cSopenharmony_ci        #[serde(skip)]
7257e2e9c0cSopenharmony_ci        #[allow(dead_code)]
7267e2e9c0cSopenharmony_ci        String(String),
7277e2e9c0cSopenharmony_ci        #[serde(other)]
7287e2e9c0cSopenharmony_ci        Unknown,
7297e2e9c0cSopenharmony_ci    }
7307e2e9c0cSopenharmony_ci
7317e2e9c0cSopenharmony_ci    #[derive(Serialize)]
7327e2e9c0cSopenharmony_ci    #[repr(packed)]
7337e2e9c0cSopenharmony_ci    struct Packed {
7347e2e9c0cSopenharmony_ci        x: u8,
7357e2e9c0cSopenharmony_ci        y: u16,
7367e2e9c0cSopenharmony_ci    }
7377e2e9c0cSopenharmony_ci
7387e2e9c0cSopenharmony_ci    macro_rules! deriving {
7397e2e9c0cSopenharmony_ci        ($field:ty) => {
7407e2e9c0cSopenharmony_ci            #[derive(Deserialize)]
7417e2e9c0cSopenharmony_ci            struct MacroRules<'a> {
7427e2e9c0cSopenharmony_ci                #[allow(dead_code)]
7437e2e9c0cSopenharmony_ci                field: $field,
7447e2e9c0cSopenharmony_ci            }
7457e2e9c0cSopenharmony_ci        };
7467e2e9c0cSopenharmony_ci    }
7477e2e9c0cSopenharmony_ci
7487e2e9c0cSopenharmony_ci    deriving!(&'a str);
7497e2e9c0cSopenharmony_ci
7507e2e9c0cSopenharmony_ci    macro_rules! mac {
7517e2e9c0cSopenharmony_ci        ($($tt:tt)*) => {
7527e2e9c0cSopenharmony_ci            $($tt)*
7537e2e9c0cSopenharmony_ci        };
7547e2e9c0cSopenharmony_ci    }
7557e2e9c0cSopenharmony_ci
7567e2e9c0cSopenharmony_ci    #[derive(Deserialize)]
7577e2e9c0cSopenharmony_ci    struct BorrowLifetimeInsideMacro<'a> {
7587e2e9c0cSopenharmony_ci        #[serde(borrow = "'a")]
7597e2e9c0cSopenharmony_ci        #[allow(dead_code)]
7607e2e9c0cSopenharmony_ci        f: mac!(Cow<'a, str>),
7617e2e9c0cSopenharmony_ci    }
7627e2e9c0cSopenharmony_ci
7637e2e9c0cSopenharmony_ci    #[derive(Serialize)]
7647e2e9c0cSopenharmony_ci    struct Struct {
7657e2e9c0cSopenharmony_ci        #[serde(serialize_with = "vec_first_element")]
7667e2e9c0cSopenharmony_ci        vec: Vec<Self>,
7677e2e9c0cSopenharmony_ci    }
7687e2e9c0cSopenharmony_ci
7697e2e9c0cSopenharmony_ci    #[derive(Deserialize)]
7707e2e9c0cSopenharmony_ci    #[serde(bound(deserialize = "[&'de str; N]: Copy"))]
7717e2e9c0cSopenharmony_ci    struct GenericUnitStruct<const N: usize>;
7727e2e9c0cSopenharmony_ci}
7737e2e9c0cSopenharmony_ci
7747e2e9c0cSopenharmony_ci//////////////////////////////////////////////////////////////////////////
7757e2e9c0cSopenharmony_ci
7767e2e9c0cSopenharmony_cifn assert<T: Serialize + DeserializeOwned>() {}
7777e2e9c0cSopenharmony_cifn assert_ser<T: Serialize>() {}
7787e2e9c0cSopenharmony_ci
7797e2e9c0cSopenharmony_citrait SerializeWith {
7807e2e9c0cSopenharmony_ci    fn serialize_with<S: Serializer>(_: &Self, _: S) -> StdResult<S::Ok, S::Error>;
7817e2e9c0cSopenharmony_ci}
7827e2e9c0cSopenharmony_ci
7837e2e9c0cSopenharmony_citrait DeserializeWith: Sized {
7847e2e9c0cSopenharmony_ci    fn deserialize_with<'de, D: Deserializer<'de>>(_: D) -> StdResult<Self, D::Error>;
7857e2e9c0cSopenharmony_ci}
7867e2e9c0cSopenharmony_ci
7877e2e9c0cSopenharmony_ci// Implements neither Serialize nor Deserialize
7887e2e9c0cSopenharmony_cipub struct X;
7897e2e9c0cSopenharmony_ci
7907e2e9c0cSopenharmony_cipub fn ser_x<S: Serializer>(_: &X, _: S) -> StdResult<S::Ok, S::Error> {
7917e2e9c0cSopenharmony_ci    unimplemented!()
7927e2e9c0cSopenharmony_ci}
7937e2e9c0cSopenharmony_ci
7947e2e9c0cSopenharmony_cipub fn de_x<'de, D: Deserializer<'de>>(_: D) -> StdResult<X, D::Error> {
7957e2e9c0cSopenharmony_ci    unimplemented!()
7967e2e9c0cSopenharmony_ci}
7977e2e9c0cSopenharmony_ci
7987e2e9c0cSopenharmony_cimod both_x {
7997e2e9c0cSopenharmony_ci    pub use super::{de_x as deserialize, ser_x as serialize};
8007e2e9c0cSopenharmony_ci}
8017e2e9c0cSopenharmony_ci
8027e2e9c0cSopenharmony_ciimpl SerializeWith for X {
8037e2e9c0cSopenharmony_ci    fn serialize_with<S: Serializer>(_: &Self, _: S) -> StdResult<S::Ok, S::Error> {
8047e2e9c0cSopenharmony_ci        unimplemented!()
8057e2e9c0cSopenharmony_ci    }
8067e2e9c0cSopenharmony_ci}
8077e2e9c0cSopenharmony_ci
8087e2e9c0cSopenharmony_ciimpl DeserializeWith for X {
8097e2e9c0cSopenharmony_ci    fn deserialize_with<'de, D: Deserializer<'de>>(_: D) -> StdResult<Self, D::Error> {
8107e2e9c0cSopenharmony_ci        unimplemented!()
8117e2e9c0cSopenharmony_ci    }
8127e2e9c0cSopenharmony_ci}
8137e2e9c0cSopenharmony_ci
8147e2e9c0cSopenharmony_cipub fn serialize_some_unit_variant<S>(_: S) -> StdResult<S::Ok, S::Error>
8157e2e9c0cSopenharmony_ciwhere
8167e2e9c0cSopenharmony_ci    S: Serializer,
8177e2e9c0cSopenharmony_ci{
8187e2e9c0cSopenharmony_ci    unimplemented!()
8197e2e9c0cSopenharmony_ci}
8207e2e9c0cSopenharmony_ci
8217e2e9c0cSopenharmony_cipub fn deserialize_some_unit_variant<'de, D>(_: D) -> StdResult<(), D::Error>
8227e2e9c0cSopenharmony_ciwhere
8237e2e9c0cSopenharmony_ci    D: Deserializer<'de>,
8247e2e9c0cSopenharmony_ci{
8257e2e9c0cSopenharmony_ci    unimplemented!()
8267e2e9c0cSopenharmony_ci}
8277e2e9c0cSopenharmony_ci
8287e2e9c0cSopenharmony_cipub fn serialize_some_other_variant<S>(_: &str, _: &u8, _: S) -> StdResult<S::Ok, S::Error>
8297e2e9c0cSopenharmony_ciwhere
8307e2e9c0cSopenharmony_ci    S: Serializer,
8317e2e9c0cSopenharmony_ci{
8327e2e9c0cSopenharmony_ci    unimplemented!()
8337e2e9c0cSopenharmony_ci}
8347e2e9c0cSopenharmony_ci
8357e2e9c0cSopenharmony_cipub fn deserialize_some_other_variant<'de, D>(_: D) -> StdResult<(String, u8), D::Error>
8367e2e9c0cSopenharmony_ciwhere
8377e2e9c0cSopenharmony_ci    D: Deserializer<'de>,
8387e2e9c0cSopenharmony_ci{
8397e2e9c0cSopenharmony_ci    unimplemented!()
8407e2e9c0cSopenharmony_ci}
8417e2e9c0cSopenharmony_ci
8427e2e9c0cSopenharmony_cipub fn is_zero(n: &u8) -> bool {
8437e2e9c0cSopenharmony_ci    *n == 0
8447e2e9c0cSopenharmony_ci}
8457e2e9c0cSopenharmony_ci
8467e2e9c0cSopenharmony_cifn vec_first_element<T, S>(vec: &[T], serializer: S) -> StdResult<S::Ok, S::Error>
8477e2e9c0cSopenharmony_ciwhere
8487e2e9c0cSopenharmony_ci    T: Serialize,
8497e2e9c0cSopenharmony_ci    S: Serializer,
8507e2e9c0cSopenharmony_ci{
8517e2e9c0cSopenharmony_ci    vec.first().serialize(serializer)
8527e2e9c0cSopenharmony_ci}
8537e2e9c0cSopenharmony_ci
8547e2e9c0cSopenharmony_ci//////////////////////////////////////////////////////////////////////////
8557e2e9c0cSopenharmony_ci
8567e2e9c0cSopenharmony_ci#[derive(Debug, PartialEq, Deserialize)]
8577e2e9c0cSopenharmony_ci#[serde(tag = "tag")]
8587e2e9c0cSopenharmony_cienum InternallyTagged {
8597e2e9c0cSopenharmony_ci    #[serde(deserialize_with = "deserialize_generic")]
8607e2e9c0cSopenharmony_ci    Unit,
8617e2e9c0cSopenharmony_ci
8627e2e9c0cSopenharmony_ci    #[serde(deserialize_with = "deserialize_generic")]
8637e2e9c0cSopenharmony_ci    Newtype(i32),
8647e2e9c0cSopenharmony_ci
8657e2e9c0cSopenharmony_ci    #[serde(deserialize_with = "deserialize_generic")]
8667e2e9c0cSopenharmony_ci    Struct { f1: String, f2: u8 },
8677e2e9c0cSopenharmony_ci}
8687e2e9c0cSopenharmony_ci
8697e2e9c0cSopenharmony_cifn deserialize_generic<'de, T, D>(deserializer: D) -> StdResult<T, D::Error>
8707e2e9c0cSopenharmony_ciwhere
8717e2e9c0cSopenharmony_ci    T: Deserialize<'de>,
8727e2e9c0cSopenharmony_ci    D: Deserializer<'de>,
8737e2e9c0cSopenharmony_ci{
8747e2e9c0cSopenharmony_ci    T::deserialize(deserializer)
8757e2e9c0cSopenharmony_ci}
8767e2e9c0cSopenharmony_ci
8777e2e9c0cSopenharmony_ci//////////////////////////////////////////////////////////////////////////
8787e2e9c0cSopenharmony_ci
8797e2e9c0cSopenharmony_ci#[repr(packed)]
8807e2e9c0cSopenharmony_cipub struct RemotePacked {
8817e2e9c0cSopenharmony_ci    pub a: u16,
8827e2e9c0cSopenharmony_ci    pub b: u32,
8837e2e9c0cSopenharmony_ci}
8847e2e9c0cSopenharmony_ci
8857e2e9c0cSopenharmony_ci#[derive(Serialize)]
8867e2e9c0cSopenharmony_ci#[repr(packed)]
8877e2e9c0cSopenharmony_ci#[serde(remote = "RemotePacked")]
8887e2e9c0cSopenharmony_cipub struct RemotePackedDef {
8897e2e9c0cSopenharmony_ci    a: u16,
8907e2e9c0cSopenharmony_ci    b: u32,
8917e2e9c0cSopenharmony_ci}
8927e2e9c0cSopenharmony_ci
8937e2e9c0cSopenharmony_ciimpl Drop for RemotePackedDef {
8947e2e9c0cSopenharmony_ci    fn drop(&mut self) {}
8957e2e9c0cSopenharmony_ci}
8967e2e9c0cSopenharmony_ci
8977e2e9c0cSopenharmony_ci#[repr(packed)]
8987e2e9c0cSopenharmony_cipub struct RemotePackedNonCopy {
8997e2e9c0cSopenharmony_ci    pub a: u16,
9007e2e9c0cSopenharmony_ci    pub b: String,
9017e2e9c0cSopenharmony_ci}
9027e2e9c0cSopenharmony_ci
9037e2e9c0cSopenharmony_ci#[derive(Deserialize)]
9047e2e9c0cSopenharmony_ci#[repr(packed)]
9057e2e9c0cSopenharmony_ci#[serde(remote = "RemotePackedNonCopy")]
9067e2e9c0cSopenharmony_cipub struct RemotePackedNonCopyDef {
9077e2e9c0cSopenharmony_ci    a: u16,
9087e2e9c0cSopenharmony_ci    b: String,
9097e2e9c0cSopenharmony_ci}
9107e2e9c0cSopenharmony_ci
9117e2e9c0cSopenharmony_ciimpl Drop for RemotePackedNonCopyDef {
9127e2e9c0cSopenharmony_ci    fn drop(&mut self) {}
9137e2e9c0cSopenharmony_ci}
914