Skip to content

Commit c6bd6b4

Browse files
Delete Decoder::read_enum
1 parent 60b71f5 commit c6bd6b4

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

compiler/rustc_macros/src/serialize.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,15 @@ fn decodable_body(
7373
variants.len()
7474
);
7575
quote! {
76-
::rustc_serialize::Decoder::read_enum(
76+
::rustc_serialize::Decoder::read_enum_variant(
7777
__decoder,
78-
|__decoder| {
79-
::rustc_serialize::Decoder::read_enum_variant(
80-
__decoder,
81-
&[#names],
82-
|__decoder, __variant_idx| {
83-
match __variant_idx {
84-
#match_inner
85-
_ => panic!(#message),
86-
}
87-
})
88-
}
89-
)
78+
&[#names],
79+
|__decoder, __variant_idx| {
80+
match __variant_idx {
81+
#match_inner
82+
_ => panic!(#message),
83+
}
84+
})
9085
}
9186
}
9287
};

compiler/rustc_serialize/src/serialize.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,6 @@ pub trait Decoder {
201201
fn read_str(&mut self) -> Cow<'_, str>;
202202
fn read_raw_bytes_into(&mut self, s: &mut [u8]);
203203

204-
// Compound types:
205-
#[inline]
206-
fn read_enum<T, F>(&mut self, f: F) -> T
207-
where
208-
F: FnOnce(&mut Self) -> T,
209-
{
210-
f(self)
211-
}
212-
213204
#[inline]
214205
fn read_enum_variant<T, F>(&mut self, _names: &[&str], mut f: F) -> T
215206
where
@@ -264,12 +255,10 @@ pub trait Decoder {
264255
where
265256
F: FnMut(&mut Self, bool) -> T,
266257
{
267-
self.read_enum(move |this| {
268-
this.read_enum_variant(&["None", "Some"], move |this, idx| match idx {
269-
0 => f(this, false),
270-
1 => f(this, true),
271-
_ => panic!("read_option: expected 0 for None or 1 for Some"),
272-
})
258+
self.read_enum_variant(&["None", "Some"], move |this, idx| match idx {
259+
0 => f(this, false),
260+
1 => f(this, true),
261+
_ => panic!("read_option: expected 0 for None or 1 for Some"),
273262
})
274263
}
275264

@@ -582,12 +571,10 @@ impl<S: Encoder, T1: Encodable<S>, T2: Encodable<S>> Encodable<S> for Result<T1,
582571

583572
impl<D: Decoder, T1: Decodable<D>, T2: Decodable<D>> Decodable<D> for Result<T1, T2> {
584573
fn decode(d: &mut D) -> Result<T1, T2> {
585-
d.read_enum(|d| {
586-
d.read_enum_variant(&["Ok", "Err"], |d, disr| match disr {
587-
0 => Ok(d.read_enum_variant_arg(|d| T1::decode(d))),
588-
1 => Err(d.read_enum_variant_arg(|d| T2::decode(d))),
589-
_ => panic!("Encountered invalid discriminant while decoding `Result`."),
590-
})
574+
d.read_enum_variant(&["Ok", "Err"], |d, disr| match disr {
575+
0 => Ok(d.read_enum_variant_arg(|d| T1::decode(d))),
576+
1 => Err(d.read_enum_variant_arg(|d| T2::decode(d))),
577+
_ => panic!("Encountered invalid discriminant while decoding `Result`."),
591578
})
592579
}
593580
}

0 commit comments

Comments
 (0)