From e24dbc418ddf3c1cc651f7483a1df353f4ce9e92 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 23 Jan 2021 20:41:43 -0800 Subject: [PATCH] Skip another clone of the fallthrough arm --- serde_derive/src/de.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index e7c71835..90d0ab7c 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -2141,28 +2141,33 @@ fn deserialize_identifier( (None, None, None, None) }; - let fallthrough_arm = if let Some(fallthrough) = fallthrough.clone() { + let fallthrough_arm_tokens; + let fallthrough_arm = if let Some(fallthrough) = &fallthrough { fallthrough } else if is_variant { - quote! { + fallthrough_arm_tokens = quote! { _serde::__private::Err(_serde::de::Error::unknown_variant(__value, VARIANTS)) - } + }; + &fallthrough_arm_tokens } else { - quote! { + fallthrough_arm_tokens = quote! { _serde::__private::Err(_serde::de::Error::unknown_field(__value, FIELDS)) - } + }; + &fallthrough_arm_tokens }; - let u64_fallthrough_arm = if let Some(fallthrough) = fallthrough { + let u64_fallthrough_arm_tokens; + let u64_fallthrough_arm = if let Some(fallthrough) = &fallthrough { fallthrough } else { let fallthrough_msg = format!("{} index 0 <= i < {}", index_expecting, fields.len()); - quote! { + u64_fallthrough_arm_tokens = quote! { _serde::__private::Err(_serde::de::Error::invalid_value( _serde::de::Unexpected::Unsigned(__value), &#fallthrough_msg, )) - } + }; + &u64_fallthrough_arm_tokens }; let variant_indices = 0_u64..;