Skip to content

Commit a421b63

Browse files
Delete read_enum_variant_arg
1 parent c87060a commit a421b63

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

compiler/rustc_macros/src/serialize.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,20 @@ fn decode_field(field: &syn::Field, index: usize, is_struct: bool) -> proc_macro
9696
} else {
9797
quote! { ::rustc_serialize::Decodable::decode }
9898
};
99-
let (decode_method, opt_field_name) = if is_struct {
99+
let __decoder = quote! { __decoder };
100+
let decode_call = if is_struct {
100101
let field_name = field.ident.as_ref().map_or_else(|| index.to_string(), |i| i.to_string());
101-
(proc_macro2::Ident::new("read_struct_field", field_span), quote! { #field_name, })
102+
let decode_method = proc_macro2::Ident::new("read_struct_field", field_span);
103+
// Use the span of the field for the method call, so
104+
// that backtraces will point to the field.
105+
quote_spanned! {field_span=>
106+
::rustc_serialize::Decoder::#decode_method(
107+
#__decoder, #field_name, #decode_inner_method)
108+
}
102109
} else {
103-
(proc_macro2::Ident::new("read_enum_variant_arg", field_span), quote! {})
104-
};
105-
106-
let __decoder = quote! { __decoder };
107-
// Use the span of the field for the method call, so
108-
// that backtraces will point to the field.
109-
let decode_call = quote_spanned! {field_span=>
110-
::rustc_serialize::Decoder::#decode_method(
111-
#__decoder, #opt_field_name #decode_inner_method)
110+
// Use the span of the field for the method call, so
111+
// that backtraces will point to the field.
112+
quote_spanned! {field_span=> #decode_inner_method(#__decoder) }
112113
};
113114

114115
quote! { #decode_call }

compiler/rustc_serialize/src/serialize.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,6 @@ pub trait Decoder {
210210
f(self, disr)
211211
}
212212

213-
#[inline]
214-
fn read_enum_variant_arg<T, F>(&mut self, f: F) -> T
215-
where
216-
F: FnOnce(&mut Self) -> T,
217-
{
218-
f(self)
219-
}
220-
221213
#[inline]
222214
fn read_struct<T, F>(&mut self, f: F) -> T
223215
where
@@ -572,8 +564,8 @@ impl<S: Encoder, T1: Encodable<S>, T2: Encodable<S>> Encodable<S> for Result<T1,
572564
impl<D: Decoder, T1: Decodable<D>, T2: Decodable<D>> Decodable<D> for Result<T1, T2> {
573565
fn decode(d: &mut D) -> Result<T1, T2> {
574566
d.read_enum_variant(|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))),
567+
0 => Ok(T1::decode(d)),
568+
1 => Err(T2::decode(d)),
577569
_ => panic!("Encountered invalid discriminant while decoding `Result`."),
578570
})
579571
}

0 commit comments

Comments
 (0)