ronantakizawa/codereview-bench huggingface dataset:
Repository: serde-rs/serde
File: src/bytes.rs (Rust)

Code before:
        where S: ser::Serializer
    {
        serializer.visit_bytes(self.bytes)
    }
}

///////////////////////////////////////////////////////////////////////////////

/// `ByteBuf` wraps a `Vec<u8>` in order to hook into serialize and from deserialize a byte array.
#[derive(Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct ByteBuf {
    bytes: Vec<u8>,
}

impl ByteBuf {
    pub fn new() -> Self {
        ByteBuf {
            bytes: Vec::new(),
        }
    }

    pub fn with_capacity(cap: usize) -> Self {
        ByteBuf {
            bytes: Vec::with_capacity(cap)
        }
    }

    pub fn as_vec(self) -> Vec<u8> {
        self.bytes
    }
}

impl fmt::Debug for ByteBuf {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "b\"{}\"", escape_bytestring(self.bytes.as_ref()))
    }
}

impl<T> From<T> for ByteBuf where T: Into<Vec<u8>> {
    fn from(bytes: T) -> Self {
        ByteBuf {
            bytes: bytes.into(),
        }
    }
}

impl AsRef<Vec<u8>> for ByteBuf {
    fn as_ref(&self) -> &Vec<u8> {
        &self.bytes
    }
}

Review comment (suggestion):
Well, the message actually mentions `From` implementations, not `Into`.

Anyway, committed this change.


Code after:
    {
        serializer.visit_bytes(self.bytes)
    }
}

///////////////////////////////////////////////////////////////////////////////

/// `ByteBuf` wraps a `Vec<u8>` in order to hook into serialize and from deserialize a byte array.
#[derive(Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct ByteBuf {
    bytes: Vec<u8>,
}

impl ByteBuf {
    pub fn new() -> Self {
        ByteBuf {
            bytes: Vec::new(),
        }
    }

    pub fn with_capacity(cap: usize) -> Self {
        ByteBuf {
            bytes: Vec::with_capacity(cap)
        }
    }
}

impl fmt::Debug for ByteBuf {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "b\"{}\"", escape_bytestring(self.bytes.as_ref()))
    }
}

impl Into<Vec<u8>> for ByteBuf {
    fn into(self) -> Vec<u8> {
        self.bytes
    }
}

impl From<Vec<u8>> for ByteBuf {
    fn from(bytes: Vec<u8>) -> Self {
        ByteBuf {
            bytes: bytes,
        }
    }
}

impl AsRef<Vec<u8>> for ByteBuf {
    fn as_ref(&self) -> &Vec<u8> {
        &self.bytes
    }
Repository: serde-rs/serde
File: src/bytes.rs (Rust)

Code before:
        where S: ser::Serializer
    {
        serializer.visit_bytes(self.bytes)
    }
}

///////////////////////////////////////////////////////////////////////////////

/// `ByteBuf` wraps a `Vec<u8>` in order to hook into serialize and from deserialize a byte array.
#[derive(Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct ByteBuf {
    bytes: Vec<u8>,
}

impl ByteBuf {
    pub fn new() -> Self {
        ByteBuf {
            bytes: Vec::new(),
        }
    }

    pub fn with_capacity(cap: usize) -> Self {
        ByteBuf {
            bytes: Vec::with_capacity(cap)
        }
    }

    pub fn as_vec(self) -> Vec<u8> {
        self.bytes
    }
}

impl fmt::Debug for ByteBuf {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "b\"{}\"", escape_bytestring(self.bytes.as_ref()))
    }
}

impl<T> From<T> for ByteBuf where T: Into<Vec<u8>> {
    fn from(bytes: T) -> Self {
        ByteBuf {
            bytes: bytes.into(),
        }
    }
}

impl AsRef<Vec<u8>> for ByteBuf {
    fn as_ref(&self) -> &Vec<u8> {
        &self.bytes
    }
}

Review comment (suggestion):
It would be generated if there was `impl From<ByteBuf> for Vec<u8>`, not `impl From<Vec<u8>> for ByteBuf`


Code after:
    {
        serializer.visit_bytes(self.bytes)
    }
}

///////////////////////////////////////////////////////////////////////////////

/// `ByteBuf` wraps a `Vec<u8>` in order to hook into serialize and from deserialize a byte array.
#[derive(Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct ByteBuf {
    bytes: Vec<u8>,
}

impl ByteBuf {
    pub fn new() -> Self {
        ByteBuf {
            bytes: Vec::new(),
        }
    }

    pub fn with_capacity(cap: usize) -> Self {
        ByteBuf {
            bytes: Vec::with_capacity(cap)
        }
    }
}

impl fmt::Debug for ByteBuf {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "b\"{}\"", escape_bytestring(self.bytes.as_ref()))
    }
}

impl Into<Vec<u8>> for ByteBuf {
    fn into(self) -> Vec<u8> {
        self.bytes
    }
}

impl From<Vec<u8>> for ByteBuf {
    fn from(bytes: Vec<u8>) -> Self {
        ByteBuf {
            bytes: bytes,
        }
    }
}

impl AsRef<Vec<u8>> for ByteBuf {
    fn as_ref(&self) -> &Vec<u8> {
        &self.bytes
    }
Repository: serde-rs/serde
File: src/bytes.rs (Rust)

Code before:
        where S: ser::Serializer
    {
        serializer.visit_bytes(self.bytes)
    }
}

///////////////////////////////////////////////////////////////////////////////

/// `ByteBuf` wraps a `Vec<u8>` in order to hook into serialize and from deserialize a byte array.
#[derive(Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct ByteBuf {
    bytes: Vec<u8>,
}

impl ByteBuf {
    pub fn new() -> Self {
        ByteBuf {
            bytes: Vec::new(),
        }
    }

    pub fn with_capacity(cap: usize) -> Self {
        ByteBuf {
            bytes: Vec::with_capacity(cap)
        }
    }

    pub fn as_vec(self) -> Vec<u8> {
        self.bytes
    }
}

impl fmt::Debug for ByteBuf {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "b\"{}\"", escape_bytestring(self.bytes.as_ref()))
    }
}

impl<T> From<T> for ByteBuf where T: Into<Vec<u8>> {
    fn from(bytes: T) -> Self {
        ByteBuf {
            bytes: bytes.into(),
        }
    }
}

impl AsRef<Vec<u8>> for ByteBuf {
    fn as_ref(&self) -> &Vec<u8> {
        &self.bytes
    }
}

Review comment (suggestion):
oh right... I got very confused with all those `From` and `Into`... sorry about that


Code after:
    {
        serializer.visit_bytes(self.bytes)
    }
}

///////////////////////////////////////////////////////////////////////////////

/// `ByteBuf` wraps a `Vec<u8>` in order to hook into serialize and from deserialize a byte array.
#[derive(Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct ByteBuf {
    bytes: Vec<u8>,
}

impl ByteBuf {
    pub fn new() -> Self {
        ByteBuf {
            bytes: Vec::new(),
        }
    }

    pub fn with_capacity(cap: usize) -> Self {
        ByteBuf {
            bytes: Vec::with_capacity(cap)
        }
    }
}

impl fmt::Debug for ByteBuf {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "b\"{}\"", escape_bytestring(self.bytes.as_ref()))
    }
}

impl Into<Vec<u8>> for ByteBuf {
    fn into(self) -> Vec<u8> {
        self.bytes
    }
}

impl From<Vec<u8>> for ByteBuf {
    fn from(bytes: Vec<u8>) -> Self {
        ByteBuf {
            bytes: bytes,
        }
    }
}

impl AsRef<Vec<u8>> for ByteBuf {
    fn as_ref(&self) -> &Vec<u8> {
        &self.bytes
    }
Repository: serde-rs/serde
File: serde_tests/tests/token.rs (Rust)

Code before:
    EndOfStreamError,
    UnknownFieldError(String),
    UnknownVariantError(String),
    MissingFieldError(&'static str),
    InvalidName(&'static str),
    InvalidValue(String),
    UnexpectedToken(Token<'static>),
    ValueError(value::Error),
}

impl ser::Error for Error {
    fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }

    fn invalid_value(msg: &str) -> Error {
        Error::InvalidValue(msg.to_owned())
    }
}

impl de::Error for Error {
    fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }

    fn end_of_stream() -> Error { Error::EndOfStreamError }

    fn invalid_value(msg: &str) -> Error {
        Error::InvalidValue(msg.to_owned())
    }

    fn unknown_field(field: &str) -> Error {
        Error::UnknownFieldError(field.to_owned())
    }

    fn unknown_variant(variant: &str) -> Error {
        Error::UnknownVariantError(variant.to_owned())
    }

    fn missing_field(field: &'static str) -> Error {
        Error::MissingFieldError(field)
    }
}

impl fmt::Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        formatter.write_str(format!("{:?}", self).as_ref())
    }
}

impl error::Error for Error {
    fn description(&self) -> &str {
        "Serde Deserialization Error"
    }


Review comment (refactor):
I think `de::Error` deserves a new method `duplicate_field(field: &'static str)`. We already have `unknown_field` and `missing_field`. The default impl could forward to `invalid_value` for now, and we can add an issue for 0.8 to remove that default impl.


Code after:
    EndOfStreamError,
    UnknownFieldError(String),
    UnknownVariantError(String),
    MissingFieldError(&'static str),
    DuplicateFieldError(&'static str),
    InvalidName(&'static str),
    InvalidValue(String),
    UnexpectedToken(Token<'static>),
    ValueError(value::Error),
}

impl ser::Error for Error {
    fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }

    fn invalid_value(msg: &str) -> Error {
        Error::InvalidValue(msg.to_owned())
    }
}

impl de::Error for Error {
    fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }

    fn end_of_stream() -> Error { Error::EndOfStreamError }

    fn invalid_value(msg: &str) -> Error {
        Error::InvalidValue(msg.to_owned())
    }

    fn unknown_field(field: &str) -> Error {
        Error::UnknownFieldError(field.to_owned())
    }

    fn unknown_variant(variant: &str) -> Error {
        Error::UnknownVariantError(variant.to_owned())
    }

    fn missing_field(field: &'static str) -> Error {
        Error::MissingFieldError(field)
    }

    fn duplicate_field(field: &'static str) -> Error {
        Error::DuplicateFieldError(field)
    }
}

impl fmt::Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        formatter.write_str(format!("{:?}", self).as_ref())
    }
}
Repository: serde-rs/serde
File: serde_tests/tests/token.rs (Rust)

Code before:
    EndOfStreamError,
    UnknownFieldError(String),
    UnknownVariantError(String),
    MissingFieldError(&'static str),
    InvalidName(&'static str),
    InvalidValue(String),
    UnexpectedToken(Token<'static>),
    ValueError(value::Error),
}

impl ser::Error for Error {
    fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }

    fn invalid_value(msg: &str) -> Error {
        Error::InvalidValue(msg.to_owned())
    }
}

impl de::Error for Error {
    fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }

    fn end_of_stream() -> Error { Error::EndOfStreamError }

    fn invalid_value(msg: &str) -> Error {
        Error::InvalidValue(msg.to_owned())
    }

    fn unknown_field(field: &str) -> Error {
        Error::UnknownFieldError(field.to_owned())
    }

    fn unknown_variant(variant: &str) -> Error {
        Error::UnknownVariantError(variant.to_owned())
    }

    fn missing_field(field: &'static str) -> Error {
        Error::MissingFieldError(field)
    }
}

impl fmt::Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        formatter.write_str(format!("{:?}", self).as_ref())
    }
}

impl error::Error for Error {
    fn description(&self) -> &str {
        "Serde Deserialization Error"
    }


Review comment (suggestion):
Because I was confused on how Error is implemented ;)


Code after:
    EndOfStreamError,
    UnknownFieldError(String),
    UnknownVariantError(String),
    MissingFieldError(&'static str),
    DuplicateFieldError(&'static str),
    InvalidName(&'static str),
    InvalidValue(String),
    UnexpectedToken(Token<'static>),
    ValueError(value::Error),
}

impl ser::Error for Error {
    fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }

    fn invalid_value(msg: &str) -> Error {
        Error::InvalidValue(msg.to_owned())
    }
}

impl de::Error for Error {
    fn custom<T: Into<String>>(_: T) -> Error { Error::SyntaxError }

    fn end_of_stream() -> Error { Error::EndOfStreamError }

    fn invalid_value(msg: &str) -> Error {
        Error::InvalidValue(msg.to_owned())
    }

    fn unknown_field(field: &str) -> Error {
        Error::UnknownFieldError(field.to_owned())
    }

    fn unknown_variant(variant: &str) -> Error {
        Error::UnknownVariantError(variant.to_owned())
    }

    fn missing_field(field: &'static str) -> Error {
        Error::MissingFieldError(field)
    }

    fn duplicate_field(field: &'static str) -> Error {
        Error::DuplicateFieldError(field)
    }
}

impl fmt::Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        formatter.write_str(format!("{:?}", self).as_ref())
    }
}
Repository: serde-rs/serde
File: serde_codegen/src/ser.rs (Rust)

Code before:

fn serialize_tuple_struct(
    cx: &ExtCtxt,
    builder: &aster::AstBuilder,
    impl_generics: &ast::Generics,
    ty: P<ast::Ty>,
    fields: &[Field],
    item_attrs: &attr::Item,
) -> P<ast::Block> {
    let serialize_stmts = serialize_tuple_struct_visitor(
        cx,
        builder,
        ty.clone(),
        fields,
        impl_generics,
        false,
        cx.ident_of("serialize_tuple_struct_elt"),
    );

    let type_name = name_expr(builder, item_attrs.name());
    let len = serialize_stmts.len();
    let let_mut = mut_if_nonzero(cx, len);

    quote_block!(cx, {
        let $let_mut state = try!(_serializer.serialize_tuple_struct($type_name, $len));
        $serialize_stmts
        _serializer.serialize_tuple_struct_end(state)
    }).unwrap()
}

fn serialize_struct(
    cx: &ExtCtxt,
    builder: &aster::AstBuilder,
    impl_generics: &ast::Generics,
    ty: P<ast::Ty>,
    fields: &[Field],
    item_attrs: &attr::Item,
) -> P<ast::Block> {
    let serialize_fields = serialize_struct_visitor(
        cx,
        builder,
        ty.clone(),
        fields,
        impl_generics,
        false,
        cx.ident_of("serialize_struct_elt"),
    );

    let type_name = name_expr(builder, item_attrs.name());

    let serialized_fields: Vec<_> = fields.iter()

Review comment (suggestion):
@nox suggests rolling this into `$serialize_stmts` and generating:

``` rust
let state = try!(...);
let mut state = state;
```

where the initial call is never mut and `$serialize_stmts` includes "let mut state = state" if necessary.


Code after:

fn serialize_tuple_struct(
    cx: &ExtCtxt,
    builder: &aster::AstBuilder,
    impl_generics: &ast::Generics,
    ty: P<ast::Ty>,
    fields: &[Field],
    item_attrs: &attr::Item,
) -> P<ast::Block> {
    let serialize_stmts = serialize_tuple_struct_visitor(
        cx,
        builder,
        ty.clone(),
        fields,
        impl_generics,
        false,
        cx.ident_of("serialize_tuple_struct_elt"),
    );

    let type_name = name_expr(builder, item_attrs.name());
    let len = serialize_stmts.len();
    let let_mut = mut_if(cx, len > 0);

    quote_block!(cx, {
        let $let_mut state = try!(_serializer.serialize_tuple_struct($type_name, $len));
        $serialize_stmts
        _serializer.serialize_tuple_struct_end(state)
    }).unwrap()
}

fn serialize_struct(
    cx: &ExtCtxt,
    builder: &aster::AstBuilder,
    impl_generics: &ast::Generics,
    ty: P<ast::Ty>,
    fields: &[Field],
    item_attrs: &attr::Item,
) -> P<ast::Block> {
    let serialize_fields = serialize_struct_visitor(
        cx,
        builder,
        ty.clone(),
        fields,
        impl_generics,
        false,
        cx.ident_of("serialize_struct_elt"),
    );

    let type_name = name_expr(builder, item_attrs.name());

    let mut serialized_fields = fields.iter()
Repository: serde-rs/serde
File: serde/src/de/impls.rs (Rust)

Code before:

impl<T> Visitor for ArrayVisitor0<T> where T: Deserialize + Default {
    type Value = [T; 0];

    #[inline]
    fn visit_unit<E>(&mut self) -> Result<[T; 0], E>
        where E: Error,
    {
        Ok([T::default(); 0])
    }

    #[inline]
    fn visit_seq<V>(&mut self, mut visitor: V) -> Result<[T; 0], V::Error>
        where V: SeqVisitor,
    {
        try!(visitor.end());
        Ok([T::default(); 0])
    }
}

impl<T> Deserialize for [T; 0]
    where T: Deserialize + Default
{
    fn deserialize<D>(deserializer: &mut D) -> Result<[T; 0], D::Error>
        where D: Deserializer,
    {
        deserializer.deserialize_seq(ArrayVisitor0::new())
    }
}

macro_rules! array_impls {
    ($($visitor:ident, $len:expr => ($($name:ident),+),)+) => {
        $(
            struct $visitor<T> {
                marker: PhantomData<T>,
            }

            impl<T> $visitor<T> {
                /// Construct a `ArrayVisitor*<T>`.
                pub fn new() -> Self {
                    $visitor {
                        marker: PhantomData
                    }
                }
            }

            impl<T> Visitor for $visitor<T> where T: Deserialize {
                type Value = [T; $len];

                #[inline]
                fn visit_seq<V>(&mut self, mut visitor: V) -> Result<[T; $len], V::Error>

Review comment (bug):
Technically a breaking change... Let's call it a bugfix


Code after:
impl<T> Visitor for ArrayVisitor<[T; 0]> where T: Deserialize {
    type Value = [T; 0];

    #[inline]
    fn visit_unit<E>(&mut self) -> Result<[T; 0], E>
        where E: Error,
    {
        Ok([])
    }

    #[inline]
    fn visit_seq<V>(&mut self, mut visitor: V) -> Result<[T; 0], V::Error>
        where V: SeqVisitor,
    {
        try!(visitor.end());
        Ok([])
    }
}

impl<T> Deserialize for [T; 0]
    where T: Deserialize
{
    fn deserialize<D>(deserializer: &mut D) -> Result<[T; 0], D::Error>
        where D: Deserializer,
    {
        deserializer.deserialize_seq_fixed_size(0, ArrayVisitor::<[T; 0]>::new())
    }
}

macro_rules! array_impls {
    ($($len:expr => ($($name:ident)+))+) => {
        $(
            impl<T> Visitor for ArrayVisitor<[T; $len]> where T: Deserialize {
                type Value = [T; $len];

                #[inline]
                fn visit_seq<V>(&mut self, mut visitor: V) -> Result<[T; $len], V::Error>
                    where V: SeqVisitor,
                {
                    $(
                        let $name = match try!(visitor.visit()) {
                            Some(val) => val,
                            None => return Err(Error::end_of_stream()),
                        };
                    )+

                    try!(visitor.end());

                    Ok([$($name),+])
                }
            }
Repository: serde-rs/serde
File: serde/src/de/impls.rs (Rust)

Code before:
                    (Field::Ok, v) => v.newtype_variant().map(Ok),
                    (Field::Err, v) => v.newtype_variant().map(Err),
                }
            }
        }

        const VARIANTS: &'static [&'static str] = &["Ok", "Err"];

        deserializer.deserialize_enum("Result", VARIANTS, ResultVisitor(PhantomData))
    }
}

////////////////////////////////////////////////////////////////////////////////

#[cfg(feature = "std")]
use std::num::Wrapping;

#[cfg(feature = "std")]
impl<'de, T> Deserialize<'de> for Wrapping<T>
where 
    T: Deserialize<'de> 
{
    fn deserialize<D>(deserializer: D) -> Result<Wrapping<T>, D::Error> 
        where D: Deserializer<'de>
    {
        Deserialize::deserialize(deserializer).map(Wrapping)
    }
} 

Review comment (bug):
Deserializing a `Wapping<u8>` from `500` will fail. Does that match your use case?

Code after:
                    (Field::Ok, v) => v.newtype_variant().map(Ok),
                    (Field::Err, v) => v.newtype_variant().map(Err),
                }
            }
        }

        const VARIANTS: &'static [&'static str] = &["Ok", "Err"];

        deserializer.deserialize_enum("Result", VARIANTS, ResultVisitor(PhantomData))
    }
}

////////////////////////////////////////////////////////////////////////////////

#[cfg(feature = "std")]
use std::num::Wrapping;

#[cfg(feature = "std")]
impl<'de, T> Deserialize<'de> for Wrapping<T>
where 
    T: Deserialize<'de> 
{
    fn deserialize<D>(deserializer: D) -> Result<Wrapping<T>, D::Error> 
        where D: Deserializer<'de>
    {
        Deserialize::deserialize(deserializer).map(Wrapping)
    }
}
Repository: serde-rs/serde
File: serde_derive/src/ser.rs (Rust)

Code before:
    }
}

fn find_transparent_field<'a>(fields: &'a [Field<'a>]) -> &'a Field<'a> {
    let mut transparent_field = None;

    for field in fields {
        if field.attrs.skip_serializing() {
            continue;
        }
        if let syn::Type::Path(ref ty) = field.ty {
            if let Some(seg) = ty.path.segments.last() {
                if seg.into_value().ident == "PhantomData" {
                    continue;
                }
            }
        }
        if transparent_field.is_some() {
            panic!("Ambiguous transparent field");
        }
        transparent_field = Some(field);
    }

    match transparent_field {
        Some(transparent_field) => transparent_field,
        None => panic!("No field can be transparent"),
    }
}

fn serialize_into(params: &Parameters, type_into: &syn::Type) -> Fragment {
    let self_var = params.self_var;
    quote_block! {
        _serde::Serialize::serialize(
            &_serde::export::Into::<#type_into>::into(_serde::export::Clone::clone(#self_var)),
            __serializer)
    }
}

fn serialize_unit_struct(cattrs: &attr::Container) -> Fragment {
    let type_name = cattrs.name().serialize_name();

    quote_expr! {
        _serde::Serializer::serialize_unit_struct(__serializer, #type_name)
    }
}

fn serialize_newtype_struct(
    params: &Parameters,
    field: &Field,
    cattrs: &attr::Container,
) -> Fragment {

Review comment (suggestion):
That message feels suboptimal. I know why it's worded this way because I'm reading the PR, but still found it confusing

Code after:
}

fn serialize_into(params: &Parameters, type_into: &syn::Type) -> Fragment {
    let self_var = &params.self_var;
    quote_block! {
        _serde::Serialize::serialize(
            &_serde::export::Into::<#type_into>::into(_serde::export::Clone::clone(#self_var)),
            __serializer)
    }
}

fn serialize_unit_struct(cattrs: &attr::Container) -> Fragment {
    let type_name = cattrs.name().serialize_name();

    quote_expr! {
        _serde::Serializer::serialize_unit_struct(__serializer, #type_name)
    }
}

fn serialize_newtype_struct(
    params: &Parameters,
    field: &Field,
    cattrs: &attr::Container,
) -> Fragment {
    let type_name = cattrs.name().serialize_name();

    let mut field_expr = get_member(
        params,
        field,
        &Member::Unnamed(Index {
            index: 0,
            span: Span::call_site(),
        }),
    );
    if let Some(path) = field.attrs.serialize_with() {
        field_expr = wrap_serialize_field_with(params, field.ty, path, &field_expr);
    }

    let span = field.original.span();
    let func = quote_spanned!(span=> _serde::Serializer::serialize_newtype_struct);
    quote_expr! {
        #func(__serializer, #type_name, #field_expr)
    }
}

fn serialize_tuple_struct(
    params: &Parameters,
    fields: &[Field],
    cattrs: &attr::Container,
) -> Fragment {
    let serialize_stmts =