From 75614c06ee2212bf171a301e6d6e0a2f5429126f Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 9 Feb 2022 17:48:06 -0500 Subject: [PATCH] Delete Decoder::read_enum_variant --- compiler/rustc_macros/src/serialize.rs | 12 ++++-------- compiler/rustc_serialize/src/serialize.rs | 19 +++++-------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_macros/src/serialize.rs b/compiler/rustc_macros/src/serialize.rs index 783b47a49e5d..535158ffd8d8 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 3d87bea58689..10aec0294d09 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(&mut self, mut f: F) -> T - where - F: FnMut(&mut Self, usize) -> T, - { - let disr = self.read_usize(); - f(self, disr) - } - fn read_seq(&mut self, f: F) -> T where F: FnOnce(&mut Self, usize) -> T, @@ -473,11 +464,11 @@ impl> Encodable for Option { impl> Decodable for Option { fn decode(d: &mut D) -> Option { - 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, T2: Encodable> Encodable for Result, T2: Decodable> Decodable for Result { fn decode(d: &mut D) -> Result { - 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`."), - }) + } } }