Skip to content

Commit 1928895

Browse files
Delete Decoder::read_struct_field
1 parent c021ba4 commit 1928895

File tree

5 files changed

+31
-60
lines changed

5 files changed

+31
-60
lines changed

compiler/rustc_macros/src/serialize.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ fn decodable_body(
4242
}
4343
let ty_name = s.ast().ident.to_string();
4444
let decode_body = match s.variants() {
45-
[vi] => vi.construct(|field, index| decode_field(field, index, true)),
45+
[vi] => vi.construct(|field, _index| decode_field(field)),
4646
variants => {
4747
let match_inner: TokenStream = variants
4848
.iter()
4949
.enumerate()
5050
.map(|(idx, vi)| {
51-
let construct = vi.construct(|field, index| decode_field(field, index, false));
51+
let construct = vi.construct(|field, _index| decode_field(field));
5252
quote! { #idx => { #construct } }
5353
})
5454
.collect();
@@ -80,7 +80,7 @@ fn decodable_body(
8080
)
8181
}
8282

83-
fn decode_field(field: &syn::Field, index: usize, is_struct: bool) -> proc_macro2::TokenStream {
83+
fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
8484
let field_span = field.ident.as_ref().map_or(field.ty.span(), |ident| ident.span());
8585

8686
let decode_inner_method = if let syn::Type::Reference(_) = field.ty {
@@ -89,22 +89,9 @@ fn decode_field(field: &syn::Field, index: usize, is_struct: bool) -> proc_macro
8989
quote! { ::rustc_serialize::Decodable::decode }
9090
};
9191
let __decoder = quote! { __decoder };
92-
let decode_call = if is_struct {
93-
let field_name = field.ident.as_ref().map_or_else(|| index.to_string(), |i| i.to_string());
94-
let decode_method = proc_macro2::Ident::new("read_struct_field", field_span);
95-
// Use the span of the field for the method call, so
96-
// that backtraces will point to the field.
97-
quote_spanned! {field_span=>
98-
::rustc_serialize::Decoder::#decode_method(
99-
#__decoder, #field_name, #decode_inner_method)
100-
}
101-
} else {
102-
// Use the span of the field for the method call, so
103-
// that backtraces will point to the field.
104-
quote_spanned! {field_span=> #decode_inner_method(#__decoder) }
105-
};
106-
107-
quote! { #decode_call }
92+
// Use the span of the field for the method call, so
93+
// that backtraces will point to the field.
94+
quote_spanned! {field_span=> #decode_inner_method(#__decoder) }
10895
}
10996

11097
pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {

compiler/rustc_query_system/src/dep_graph/serialized.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,23 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
122122
let mut edge_list_data = Vec::with_capacity(edge_count);
123123

124124
for _index in 0..node_count {
125-
let dep_node: DepNode<K> = d.read_struct_field("node", Decodable::decode);
125+
let dep_node: DepNode<K> = Decodable::decode(d);
126126
let _i: SerializedDepNodeIndex = nodes.push(dep_node);
127127
debug_assert_eq!(_i.index(), _index);
128128

129-
let fingerprint: Fingerprint = d.read_struct_field("fingerprint", Decodable::decode);
129+
let fingerprint: Fingerprint = Decodable::decode(d);
130130
let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
131131
debug_assert_eq!(_i.index(), _index);
132132

133-
d.read_struct_field("edges", |d| {
134-
d.read_seq(|d, len| {
135-
let start = edge_list_data.len().try_into().unwrap();
136-
for _ in 0..len {
137-
let edge = d.read_seq_elt(Decodable::decode);
138-
edge_list_data.push(edge);
139-
}
140-
let end = edge_list_data.len().try_into().unwrap();
141-
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
142-
debug_assert_eq!(_i.index(), _index);
143-
})
133+
d.read_seq(|d, len| {
134+
let start = edge_list_data.len().try_into().unwrap();
135+
for _ in 0..len {
136+
let edge = d.read_seq_elt(Decodable::decode);
137+
edge_list_data.push(edge);
138+
}
139+
let end = edge_list_data.len().try_into().unwrap();
140+
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
141+
debug_assert_eq!(_i.index(), _index);
144142
})
145143
}
146144

compiler/rustc_serialize/src/serialize.rs

Lines changed: 0 additions & 8 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_struct_field<T, F>(&mut self, _f_name: &str, f: F) -> T
215-
where
216-
F: FnOnce(&mut Self) -> T,
217-
{
218-
f(self)
219-
}
220-
221213
#[inline]
222214
fn read_tuple<T, F>(&mut self, _len: usize, f: F) -> T
223215
where

compiler/rustc_span/src/def_id.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,7 @@ impl<E: Encoder> Encodable<E> for DefId {
299299

300300
impl<D: Decoder> Decodable<D> for DefId {
301301
default fn decode(d: &mut D) -> DefId {
302-
DefId {
303-
krate: d.read_struct_field("krate", Decodable::decode),
304-
index: d.read_struct_field("index", Decodable::decode),
305-
}
302+
DefId { krate: Decodable::decode(d), index: Decodable::decode(d) }
306303
}
307304
}
308305

compiler/rustc_span/src/lib.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,8 @@ impl<E: Encoder> Encodable<E> for Span {
979979
}
980980
impl<D: Decoder> Decodable<D> for Span {
981981
default fn decode(s: &mut D) -> Span {
982-
let lo = s.read_struct_field("lo", Decodable::decode);
983-
let hi = s.read_struct_field("hi", Decodable::decode);
982+
let lo = Decodable::decode(s);
983+
let hi = Decodable::decode(s);
984984

985985
Span::new(lo, hi, SyntaxContext::root(), None)
986986
}
@@ -1438,11 +1438,11 @@ impl<S: Encoder> Encodable<S> for SourceFile {
14381438

14391439
impl<D: Decoder> Decodable<D> for SourceFile {
14401440
fn decode(d: &mut D) -> SourceFile {
1441-
let name: FileName = d.read_struct_field("name", |d| Decodable::decode(d));
1442-
let src_hash: SourceFileHash = d.read_struct_field("src_hash", |d| Decodable::decode(d));
1443-
let start_pos: BytePos = d.read_struct_field("start_pos", |d| Decodable::decode(d));
1444-
let end_pos: BytePos = d.read_struct_field("end_pos", |d| Decodable::decode(d));
1445-
let lines: Vec<BytePos> = d.read_struct_field("lines", |d| {
1441+
let name: FileName = Decodable::decode(d);
1442+
let src_hash: SourceFileHash = Decodable::decode(d);
1443+
let start_pos: BytePos = Decodable::decode(d);
1444+
let end_pos: BytePos = Decodable::decode(d);
1445+
let lines: Vec<BytePos> = {
14461446
let num_lines: u32 = Decodable::decode(d);
14471447
let mut lines = Vec::with_capacity(num_lines as usize);
14481448

@@ -1469,15 +1469,12 @@ impl<D: Decoder> Decodable<D> for SourceFile {
14691469
}
14701470

14711471
lines
1472-
});
1473-
let multibyte_chars: Vec<MultiByteChar> =
1474-
d.read_struct_field("multibyte_chars", |d| Decodable::decode(d));
1475-
let non_narrow_chars: Vec<NonNarrowChar> =
1476-
d.read_struct_field("non_narrow_chars", |d| Decodable::decode(d));
1477-
let name_hash: u128 = d.read_struct_field("name_hash", |d| Decodable::decode(d));
1478-
let normalized_pos: Vec<NormalizedPos> =
1479-
d.read_struct_field("normalized_pos", |d| Decodable::decode(d));
1480-
let cnum: CrateNum = d.read_struct_field("cnum", |d| Decodable::decode(d));
1472+
};
1473+
let multibyte_chars: Vec<MultiByteChar> = Decodable::decode(d);
1474+
let non_narrow_chars: Vec<NonNarrowChar> = Decodable::decode(d);
1475+
let name_hash: u128 = Decodable::decode(d);
1476+
let normalized_pos: Vec<NormalizedPos> = Decodable::decode(d);
1477+
let cnum: CrateNum = Decodable::decode(d);
14811478
SourceFile {
14821479
name,
14831480
start_pos,

0 commit comments

Comments
 (0)