about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2022-02-09 17:48:06 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2022-02-20 18:58:23 -0500
commit75614c06ee2212bf171a301e6d6e0a2f5429126f (patch)
tree968ead33f9be7339398c6e69d5a5d1c95ce8f8b1 /compiler
parent8def096c4de13ba04617040a7848c864b171fde4 (diff)
downloadrust-75614c06ee2212bf171a301e6d6e0a2f5429126f.tar.gz
rust-75614c06ee2212bf171a301e6d6e0a2f5429126f.zip
Delete Decoder::read_enum_variant
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_macros/src/serialize.rs12
-rw-r--r--compiler/rustc_serialize/src/serialize.rs19
2 files changed, 9 insertions, 22 deletions
diff --git a/compiler/rustc_macros/src/serialize.rs b/compiler/rustc_macros/src/serialize.rs
index 783b47a49e5..535158ffd8d 100644
--- a/compiler/rustc_macros/src/serialize.rs
+++ b/compiler/rustc_macros/src/serialize.rs
@@ -58,14 +58,10 @@ fn decodable_body(
                 variants.len()
             );
             quote! {
-                ::rustc_serialize::Decoder::read_enum_variant(
-                    __decoder,
-                    |__decoder, __variant_idx| {
-                        match __variant_idx {
-                            #match_inner
-                            _ => panic!(#message),
-                        }
-                    })
+                match ::rustc_serialize::Decoder::read_usize(__decoder) {
+                    #match_inner
+                    _ => panic!(#message),
+                }
             }
         }
     };
diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs
index 3d87bea5868..10aec0294d0 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]);
 
-    #[inline]
-    fn read_enum_variant<T, F>(&mut self, mut f: F) -> T
-    where
-        F: FnMut(&mut Self, usize) -> T,
-    {
-        let disr = self.read_usize();
-        f(self, disr)
-    }
-
     fn read_seq<T, F>(&mut self, f: F) -> T
     where
         F: FnOnce(&mut Self, usize) -> T,
@@ -473,11 +464,11 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Option<T> {
 
 impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
     fn decode(d: &mut D) -> Option<T> {
-        d.read_enum_variant(move |this, idx| match idx {
+        match d.read_usize() {
             0 => None,
-            1 => Some(Decodable::decode(this)),
+            1 => Some(Decodable::decode(d)),
             _ => panic!("Encountered invalid discriminant while decoding `Option`."),
-        })
+        }
     }
 }
 
@@ -496,11 +487,11 @@ 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_variant(|d, disr| match disr {
+        match d.read_usize() {
             0 => Ok(T1::decode(d)),
             1 => Err(T2::decode(d)),
             _ => panic!("Encountered invalid discriminant while decoding `Result`."),
-        })
+        }
     }
 }