about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2022-02-09 17:10:45 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2022-02-20 18:58:22 -0500
commitc6bd6b444ca7718eca5bbd86a4438e779f31dc5e (patch)
treead83c65cc0e97f1bf122bdfec54fe4c4a425abbf
parent60b71f56e73fc139eababa00aa8f1b740cb7d445 (diff)
downloadrust-c6bd6b444ca7718eca5bbd86a4438e779f31dc5e.tar.gz
rust-c6bd6b444ca7718eca5bbd86a4438e779f31dc5e.zip
Delete Decoder::read_enum
-rw-r--r--compiler/rustc_macros/src/serialize.rs21
-rw-r--r--compiler/rustc_serialize/src/serialize.rs29
2 files changed, 16 insertions, 34 deletions
diff --git a/compiler/rustc_macros/src/serialize.rs b/compiler/rustc_macros/src/serialize.rs
index 6c5461505fa..91a076fa6f6 100644
--- a/compiler/rustc_macros/src/serialize.rs
+++ b/compiler/rustc_macros/src/serialize.rs
@@ -73,20 +73,15 @@ fn decodable_body(
                 variants.len()
             );
             quote! {
-                ::rustc_serialize::Decoder::read_enum(
+                ::rustc_serialize::Decoder::read_enum_variant(
                     __decoder,
-                    |__decoder| {
-                        ::rustc_serialize::Decoder::read_enum_variant(
-                            __decoder,
-                            &[#names],
-                            |__decoder, __variant_idx| {
-                                match __variant_idx {
-                                    #match_inner
-                                    _ => panic!(#message),
-                                }
-                            })
-                    }
-                )
+                    &[#names],
+                    |__decoder, __variant_idx| {
+                        match __variant_idx {
+                            #match_inner
+                            _ => panic!(#message),
+                        }
+                    })
             }
         }
     };
diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs
index a6172403fd6..6e0199260f8 100644
--- a/compiler/rustc_serialize/src/serialize.rs
+++ b/compiler/rustc_serialize/src/serialize.rs
@@ -201,15 +201,6 @@ pub trait Decoder {
     fn read_str(&mut self) -> Cow<'_, str>;
     fn read_raw_bytes_into(&mut self, s: &mut [u8]);
 
-    // Compound types:
-    #[inline]
-    fn read_enum<T, F>(&mut self, f: F) -> T
-    where
-        F: FnOnce(&mut Self) -> T,
-    {
-        f(self)
-    }
-
     #[inline]
     fn read_enum_variant<T, F>(&mut self, _names: &[&str], mut f: F) -> T
     where
@@ -264,12 +255,10 @@ pub trait Decoder {
     where
         F: FnMut(&mut Self, bool) -> T,
     {
-        self.read_enum(move |this| {
-            this.read_enum_variant(&["None", "Some"], move |this, idx| match idx {
-                0 => f(this, false),
-                1 => f(this, true),
-                _ => panic!("read_option: expected 0 for None or 1 for Some"),
-            })
+        self.read_enum_variant(&["None", "Some"], move |this, idx| match idx {
+            0 => f(this, false),
+            1 => f(this, true),
+            _ => panic!("read_option: expected 0 for None or 1 for Some"),
         })
     }
 
@@ -582,12 +571,10 @@ impl<S: Encoder, T1: Encodable<S>, T2: Encodable<S>> Encodable<S> for Result<T1,
 
 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(|d| {
-            d.read_enum_variant(&["Ok", "Err"], |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))),
-                _ => panic!("Encountered invalid discriminant while decoding `Result`."),
-            })
+        d.read_enum_variant(&["Ok", "Err"], |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))),
+            _ => panic!("Encountered invalid discriminant while decoding `Result`."),
         })
     }
 }