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 "cannot move out of *self which is behind a shared reference" #2592

Merged
merged 2 commits into from Aug 21, 2023
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
4 changes: 2 additions & 2 deletions serde_derive/src/ser.rs
Expand Up @@ -409,9 +409,9 @@ fn serialize_enum(params: &Parameters, variants: &[Variant], cattrs: &attr::Cont
})
.collect();

if cattrs.non_exhaustive() {
if cattrs.remote().is_some() && cattrs.non_exhaustive() {
arms.push(quote! {
unrecognized => _serde::__private::Err(_serde::ser::Error::custom(_serde::__private::ser::CannotSerializeVariant(unrecognized))),
ref unrecognized => _serde::__private::Err(_serde::ser::Error::custom(_serde::__private::ser::CannotSerializeVariant(unrecognized))),
});
}

Expand Down
12 changes: 10 additions & 2 deletions test_suite/tests/test_remote.rs
Expand Up @@ -127,7 +127,7 @@ struct Test {
enum_concrete: remote::EnumGeneric<u8>,

#[serde(with = "ErrorKindDef")]
io_error_kind: std::io::ErrorKind,
io_error_kind: ErrorKind,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -200,8 +200,16 @@ enum EnumConcrete {
Variant(u8),
}

#[derive(Debug)]
enum ErrorKind {
NotFound,
PermissionDenied,
#[allow(dead_code)]
ConnectionRefused,
}

#[derive(Serialize, Deserialize)]
#[serde(remote = "std::io::ErrorKind")]
#[serde(remote = "ErrorKind")]
#[non_exhaustive]
enum ErrorKindDef {
NotFound,
Expand Down