Delete Decoder::read_struct

This commit is contained in:
Mark Rousskov 2022-02-09 17:20:43 -05:00
parent a421b631ba
commit c021ba48a7
5 changed files with 74 additions and 98 deletions

View File

@ -42,15 +42,7 @@ fn decodable_body(
}
let ty_name = s.ast().ident.to_string();
let decode_body = match s.variants() {
[vi] => {
let construct = vi.construct(|field, index| decode_field(field, index, true));
quote! {
::rustc_serialize::Decoder::read_struct(
__decoder,
|__decoder| { #construct },
)
}
}
[vi] => vi.construct(|field, index| decode_field(field, index, true)),
variants => {
let match_inner: TokenStream = variants
.iter()

View File

@ -122,13 +122,11 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
let mut edge_list_data = Vec::with_capacity(edge_count);
for _index in 0..node_count {
d.read_struct(|d| {
let dep_node: DepNode<K> = d.read_struct_field("node", Decodable::decode);
let _i: SerializedDepNodeIndex = nodes.push(dep_node);
debug_assert_eq!(_i.index(), _index);
let fingerprint: Fingerprint =
d.read_struct_field("fingerprint", Decodable::decode);
let fingerprint: Fingerprint = d.read_struct_field("fingerprint", Decodable::decode);
let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
debug_assert_eq!(_i.index(), _index);
@ -144,7 +142,6 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
debug_assert_eq!(_i.index(), _index);
})
})
});
}
let index: FxHashMap<_, _> =

View File

@ -210,14 +210,6 @@ pub trait Decoder {
f(self, disr)
}
#[inline]
fn read_struct<T, F>(&mut self, f: F) -> T
where
F: FnOnce(&mut Self) -> T,
{
f(self)
}
#[inline]
fn read_struct_field<T, F>(&mut self, _f_name: &str, f: F) -> T
where

View File

@ -299,10 +299,10 @@ impl<E: Encoder> Encodable<E> for DefId {
impl<D: Decoder> Decodable<D> for DefId {
default fn decode(d: &mut D) -> DefId {
d.read_struct(|d| DefId {
DefId {
krate: d.read_struct_field("krate", Decodable::decode),
index: d.read_struct_field("index", Decodable::decode),
})
}
}
}

View File

@ -979,12 +979,10 @@ impl<E: Encoder> Encodable<E> for Span {
}
impl<D: Decoder> Decodable<D> for Span {
default fn decode(s: &mut D) -> Span {
s.read_struct(|d| {
let lo = d.read_struct_field("lo", Decodable::decode);
let hi = d.read_struct_field("hi", Decodable::decode);
let lo = s.read_struct_field("lo", Decodable::decode);
let hi = s.read_struct_field("hi", Decodable::decode);
Span::new(lo, hi, SyntaxContext::root(), None)
})
}
}
@ -1440,10 +1438,8 @@ impl<S: Encoder> Encodable<S> for SourceFile {
impl<D: Decoder> Decodable<D> for SourceFile {
fn decode(d: &mut D) -> SourceFile {
d.read_struct(|d| {
let name: FileName = d.read_struct_field("name", |d| Decodable::decode(d));
let src_hash: SourceFileHash =
d.read_struct_field("src_hash", |d| Decodable::decode(d));
let src_hash: SourceFileHash = d.read_struct_field("src_hash", |d| Decodable::decode(d));
let start_pos: BytePos = d.read_struct_field("start_pos", |d| Decodable::decode(d));
let end_pos: BytePos = d.read_struct_field("end_pos", |d| Decodable::decode(d));
let lines: Vec<BytePos> = d.read_struct_field("lines", |d| {
@ -1498,7 +1494,6 @@ impl<D: Decoder> Decodable<D> for SourceFile {
name_hash,
cnum,
}
})
}
}