]> git.lizzy.rs Git - rust.git/commitdiff
Delete read_enum_variant_arg
authorMark Rousskov <mark.simulacrum@gmail.com>
Wed, 9 Feb 2022 22:17:04 +0000 (17:17 -0500)
committerMark Rousskov <mark.simulacrum@gmail.com>
Sun, 20 Feb 2022 23:58:22 +0000 (18:58 -0500)
compiler/rustc_macros/src/serialize.rs
compiler/rustc_serialize/src/serialize.rs

index 8d898291e58874a4bfa9e01cda6025d0b0055e39..2c4b794ffa19e67c860abdd5a8a712de3450e789 100644 (file)
@@ -96,19 +96,20 @@ fn decode_field(field: &syn::Field, index: usize, is_struct: bool) -> proc_macro
     } else {
         quote! { ::rustc_serialize::Decodable::decode }
     };
-    let (decode_method, opt_field_name) = if is_struct {
+    let __decoder = quote! { __decoder };
+    let decode_call = if is_struct {
         let field_name = field.ident.as_ref().map_or_else(|| index.to_string(), |i| i.to_string());
-        (proc_macro2::Ident::new("read_struct_field", field_span), quote! { #field_name, })
+        let decode_method = proc_macro2::Ident::new("read_struct_field", field_span);
+        // Use the span of the field for the method call, so
+        // that backtraces will point to the field.
+        quote_spanned! {field_span=>
+            ::rustc_serialize::Decoder::#decode_method(
+                    #__decoder, #field_name, #decode_inner_method)
+        }
     } else {
-        (proc_macro2::Ident::new("read_enum_variant_arg", field_span), quote! {})
-    };
-
-    let __decoder = quote! { __decoder };
-    // Use the span of the field for the method call, so
-    // that backtraces will point to the field.
-    let decode_call = quote_spanned! {field_span=>
-        ::rustc_serialize::Decoder::#decode_method(
-                #__decoder, #opt_field_name #decode_inner_method)
+        // Use the span of the field for the method call, so
+        // that backtraces will point to the field.
+        quote_spanned! {field_span=> #decode_inner_method(#__decoder) }
     };
 
     quote! { #decode_call }
index b1a75309ccdd299a7acfaff4b4d9b6bc30788f6a..5e62a0f1eb2e62fc2f7b728d1af4e72d9c70e0b6 100644 (file)
@@ -210,14 +210,6 @@ fn read_enum_variant<T, F>(&mut self, mut f: F) -> T
         f(self, disr)
     }
 
-    #[inline]
-    fn read_enum_variant_arg<T, F>(&mut self, f: F) -> T
-    where
-        F: FnOnce(&mut Self) -> T,
-    {
-        f(self)
-    }
-
     #[inline]
     fn read_struct<T, F>(&mut self, f: F) -> T
     where
@@ -572,8 +564,8 @@ fn encode(&self, s: &mut S) -> Result<(), S::Error> {
 impl<D: Decoder, T1: Decodable<D>, T2: Decodable<D>> Decodable<D> for Result<T1, T2> {
     fn decode(d: &mut D) -> Result<T1, T2> {
         d.read_enum_variant(|d, disr| match disr {
-            0 => Ok(d.read_enum_variant_arg(|d| T1::decode(d))),
-            1 => Err(d.read_enum_variant_arg(|d| T2::decode(d))),
+            0 => Ok(T1::decode(d)),
+            1 => Err(T2::decode(d)),
             _ => panic!("Encountered invalid discriminant while decoding `Result`."),
         })
     }