mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Delete read_enum_variant_arg
This commit is contained in:
parent
c87060a72d
commit
a421b631ba
@ -96,19 +96,20 @@ fn decode_field(field: &syn::Field, index: usize, is_struct: bool) -> proc_macro
|
|||||||
} else {
|
} else {
|
||||||
quote! { ::rustc_serialize::Decodable::decode }
|
quote! { ::rustc_serialize::Decodable::decode }
|
||||||
};
|
};
|
||||||
let (decode_method, opt_field_name) = if is_struct {
|
|
||||||
let field_name = field.ident.as_ref().map_or_else(|| index.to_string(), |i| i.to_string());
|
|
||||||
(proc_macro2::Ident::new("read_struct_field", field_span), quote! { #field_name, })
|
|
||||||
} else {
|
|
||||||
(proc_macro2::Ident::new("read_enum_variant_arg", field_span), quote! {})
|
|
||||||
};
|
|
||||||
|
|
||||||
let __decoder = quote! { __decoder };
|
let __decoder = quote! { __decoder };
|
||||||
|
let decode_call = if is_struct {
|
||||||
|
let field_name = field.ident.as_ref().map_or_else(|| index.to_string(), |i| i.to_string());
|
||||||
|
let decode_method = proc_macro2::Ident::new("read_struct_field", field_span);
|
||||||
// Use the span of the field for the method call, so
|
// Use the span of the field for the method call, so
|
||||||
// that backtraces will point to the field.
|
// that backtraces will point to the field.
|
||||||
let decode_call = quote_spanned! {field_span=>
|
quote_spanned! {field_span=>
|
||||||
::rustc_serialize::Decoder::#decode_method(
|
::rustc_serialize::Decoder::#decode_method(
|
||||||
#__decoder, #opt_field_name #decode_inner_method)
|
#__decoder, #field_name, #decode_inner_method)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Use the span of the field for the method call, so
|
||||||
|
// that backtraces will point to the field.
|
||||||
|
quote_spanned! {field_span=> #decode_inner_method(#__decoder) }
|
||||||
};
|
};
|
||||||
|
|
||||||
quote! { #decode_call }
|
quote! { #decode_call }
|
||||||
|
@ -210,14 +210,6 @@ pub trait Decoder {
|
|||||||
f(self, disr)
|
f(self, disr)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn read_enum_variant_arg<T, F>(&mut self, f: F) -> T
|
|
||||||
where
|
|
||||||
F: FnOnce(&mut Self) -> T,
|
|
||||||
{
|
|
||||||
f(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn read_struct<T, F>(&mut self, f: F) -> T
|
fn read_struct<T, F>(&mut self, f: F) -> T
|
||||||
where
|
where
|
||||||
@ -572,8 +564,8 @@ 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> {
|
impl<D: Decoder, T1: Decodable<D>, T2: Decodable<D>> Decodable<D> for Result<T1, T2> {
|
||||||
fn decode(d: &mut D) -> Result<T1, T2> {
|
fn decode(d: &mut D) -> Result<T1, T2> {
|
||||||
d.read_enum_variant(|d, disr| match disr {
|
d.read_enum_variant(|d, disr| match disr {
|
||||||
0 => Ok(d.read_enum_variant_arg(|d| T1::decode(d))),
|
0 => Ok(T1::decode(d)),
|
||||||
1 => Err(d.read_enum_variant_arg(|d| T2::decode(d))),
|
1 => Err(T2::decode(d)),
|
||||||
_ => panic!("Encountered invalid discriminant while decoding `Result`."),
|
_ => panic!("Encountered invalid discriminant while decoding `Result`."),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user