Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generated Into conversion involving generic remote derive with getter #2330

Merged
merged 2 commits into from Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions serde_derive/src/de.rs
Expand Up @@ -712,8 +712,9 @@ fn deserialize_seq(

if params.has_getter {
let this_type = &params.this_type;
let (_, ty_generics, _) = params.generics.split_for_impl();
result = quote! {
_serde::__private::Into::<#this_type>::into(#result)
_serde::__private::Into::<#this_type #ty_generics>::into(#result)
};
}

Expand Down Expand Up @@ -856,8 +857,9 @@ fn deserialize_newtype_struct(
let mut result = quote!(#type_path(__field0));
if params.has_getter {
let this_type = &params.this_type;
let (_, ty_generics, _) = params.generics.split_for_impl();
result = quote! {
_serde::__private::Into::<#this_type>::into(#result)
_serde::__private::Into::<#this_type #ty_generics>::into(#result)
};
}

Expand Down Expand Up @@ -2629,8 +2631,9 @@ fn deserialize_map(
let mut result = quote!(#struct_path { #(#result),* });
if params.has_getter {
let this_type = &params.this_type;
let (_, ty_generics, _) = params.generics.split_for_impl();
result = quote! {
_serde::__private::Into::<#this_type>::into(#result)
_serde::__private::Into::<#this_type #ty_generics>::into(#result)
};
}

Expand Down
20 changes: 20 additions & 0 deletions test_suite/tests/test_remote.rs
Expand Up @@ -79,6 +79,13 @@ mod remote {
pub value: T,
}

impl<T> StructGeneric<T> {
#[allow(dead_code)]
pub fn get_value(&self) -> &T {
&self.value
}
}

pub enum EnumGeneric<T> {
Variant(T),
}
Expand Down Expand Up @@ -171,6 +178,13 @@ struct StructPubDef {
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 {
Expand Down Expand Up @@ -206,3 +220,9 @@ impl From<StructPrivDef> for remote::StructPriv {
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 }
}
}