Repository: diesel-rs/diesel
File: diesel_derives/src/field.rs (Rust)

Code before:
    }

    pub fn column_name(&self) -> syn::Ident {
        self.column_name_from_attribute
            .as_ref()
            .map(|m| m.expect_ident_value())
            .unwrap_or_else(|| match self.name {
                FieldName::Named(ref x) => x.clone(),
                _ => {
                    self.span
                        .error(
                            "All fields of tuple structs must be annotated with `#[column_name]`",
                        )
                        .emit();
                    Ident::new("unknown_column", self.span)
                }
            })
    }

    pub fn column_str_name(&self) -> String {
        self.column_name_from_attribute
            .as_ref()
            .map(|m| {
                m.str_value().unwrap_or_else(|e| {
                    e.emit();
                    "unknown_column".to_string()
                })
            })
            .unwrap_or_else(|| {
                self.span
                    .error("All fields of tuple structs must be annotated with `#[column_name]`")
                    .emit();
                "unknown_column".to_string()
            })
    }

    pub fn has_flag(&self, flag: &str) -> bool {
        self.flags.has_flag(flag)
    }

    pub fn ty_for_serialize(&self) -> Result<Option<syn::Type>, Diagnostic> {
        if let Some(meta) = self.flags.nested_item("serialize_as")? {
            let ty = meta.ty_value()?;
            Ok(Some(ty))
        } else {
            Ok(None)
        }
    }

    pub fn ty_for_deserialize(&self) -> Result<Cow<syn::Type>, Diagnostic> {
        if let Some(meta) = self.flags.nested_item("deserialize_as")? {

Review comment (suggestion):
If its a named field we should use the actual name of the field here, similary that done in the existing `column_name` function.

Code after:
    }

    pub fn column_name_ident(&self) -> syn::Ident {
        self.column_name_from_attribute
            .as_ref()
            .map(|m| m.expect_ident_value())
            .unwrap_or_else(|| match self.name {
                FieldName::Named(ref x) => x.clone(),
                _ => {
                    self.span
                        .error(
                            "All fields of tuple structs must be annotated with `#[column_name]`",
                        )
                        .emit();
                    Ident::new("unknown_column", self.span)
                }
            })
    }

    pub fn column_name_str(&self) -> String {
        self.column_name_from_attribute
            .as_ref()
            .map(|m| {
                m.str_value().unwrap_or_else(|e| {
                    e.emit();
                    m.name().segments.first().unwrap().ident.to_string()
                })
            })
            .unwrap_or_else(|| match self.name {
                FieldName::Named(ref x) => x.to_string(),
                _ => {
                    self.span
                        .error(
                            "All fields of tuple structs must be annotated with `#[column_name]`",
                        )
                        .emit();
                    "unknown_column".to_string()
                }
            })
    }

    pub fn has_flag(&self, flag: &str) -> bool {
        self.flags.has_flag(flag)
    }

    pub fn ty_for_serialize(&self) -> Result<Option<syn::Type>, Diagnostic> {
        if let Some(meta) = self.flags.nested_item("serialize_as")? {
            let ty = meta.ty_value()?;
            Ok(Some(ty))
        } else {
            Ok(None)