about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2022-02-09 17:26:17 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2022-02-20 18:58:22 -0500
commit19288951e1968abbfa552f6340a693d23e5e0254 (patch)
tree4880421657fa368a6c319b567032e5d9d19dec4e
parentc021ba48a70e69fa681ea6617512ae2028e2677a (diff)
downloadrust-19288951e1968abbfa552f6340a693d23e5e0254.tar.gz
rust-19288951e1968abbfa552f6340a693d23e5e0254.zip
Delete Decoder::read_struct_field
-rw-r--r--compiler/rustc_macros/src/serialize.rs25
-rw-r--r--compiler/rustc_query_system/src/dep_graph/serialized.rs24
-rw-r--r--compiler/rustc_serialize/src/serialize.rs8
-rw-r--r--compiler/rustc_span/src/def_id.rs5
-rw-r--r--compiler/rustc_span/src/lib.rs29
5 files changed, 31 insertions, 60 deletions
diff --git a/compiler/rustc_macros/src/serialize.rs b/compiler/rustc_macros/src/serialize.rs
index af8b85f25fd..783b47a49e5 100644
--- a/compiler/rustc_macros/src/serialize.rs
+++ b/compiler/rustc_macros/src/serialize.rs
@@ -42,13 +42,13 @@ fn decodable_body(
     }
     let ty_name = s.ast().ident.to_string();
     let decode_body = match s.variants() {
-        [vi] => vi.construct(|field, index| decode_field(field, index, true)),
+        [vi] => vi.construct(|field, _index| decode_field(field)),
         variants => {
             let match_inner: TokenStream = variants
                 .iter()
                 .enumerate()
                 .map(|(idx, vi)| {
-                    let construct = vi.construct(|field, index| decode_field(field, index, false));
+                    let construct = vi.construct(|field, _index| decode_field(field));
                     quote! { #idx => { #construct } }
                 })
                 .collect();
@@ -80,7 +80,7 @@ fn decodable_body(
     )
 }
 
-fn decode_field(field: &syn::Field, index: usize, is_struct: bool) -> proc_macro2::TokenStream {
+fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
     let field_span = field.ident.as_ref().map_or(field.ty.span(), |ident| ident.span());
 
     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
         quote! { ::rustc_serialize::Decodable::decode }
     };
     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
-        // that backtraces will point to the field.
-        quote_spanned! {field_span=>
-            ::rustc_serialize::Decoder::#decode_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 }
+    // 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) }
 }
 
 pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs
index 8c85605c030..29db5a9878e 100644
--- a/compiler/rustc_query_system/src/dep_graph/serialized.rs
+++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs
@@ -122,25 +122,23 @@ 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 {
-            let dep_node: DepNode<K> = d.read_struct_field("node", Decodable::decode);
+            let dep_node: DepNode<K> = Decodable::decode(d);
             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 = Decodable::decode(d);
             let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
             debug_assert_eq!(_i.index(), _index);
 
-            d.read_struct_field("edges", |d| {
-                d.read_seq(|d, len| {
-                    let start = edge_list_data.len().try_into().unwrap();
-                    for _ in 0..len {
-                        let edge = d.read_seq_elt(Decodable::decode);
-                        edge_list_data.push(edge);
-                    }
-                    let end = edge_list_data.len().try_into().unwrap();
-                    let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
-                    debug_assert_eq!(_i.index(), _index);
-                })
+            d.read_seq(|d, len| {
+                let start = edge_list_data.len().try_into().unwrap();
+                for _ in 0..len {
+                    let edge = d.read_seq_elt(Decodable::decode);
+                    edge_list_data.push(edge);
+                }
+                let end = edge_list_data.len().try_into().unwrap();
+                let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
+                debug_assert_eq!(_i.index(), _index);
             })
         }
 
diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs
index 1ce62d1224b..4996e02d7d7 100644
--- a/compiler/rustc_serialize/src/serialize.rs
+++ b/compiler/rustc_serialize/src/serialize.rs
@@ -211,14 +211,6 @@ pub trait Decoder {
     }
 
     #[inline]
-    fn read_struct_field<T, F>(&mut self, _f_name: &str, f: F) -> T
-    where
-        F: FnOnce(&mut Self) -> T,
-    {
-        f(self)
-    }
-
-    #[inline]
     fn read_tuple<T, F>(&mut self, _len: usize, f: F) -> T
     where
         F: FnOnce(&mut Self) -> T,
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs
index 5b6f110413a..56da7c43728 100644
--- a/compiler/rustc_span/src/def_id.rs
+++ b/compiler/rustc_span/src/def_id.rs
@@ -299,10 +299,7 @@ impl<E: Encoder> Encodable<E> for DefId {
 
 impl<D: Decoder> Decodable<D> for DefId {
     default fn decode(d: &mut D) -> DefId {
-        DefId {
-            krate: d.read_struct_field("krate", Decodable::decode),
-            index: d.read_struct_field("index", Decodable::decode),
-        }
+        DefId { krate: Decodable::decode(d), index: Decodable::decode(d) }
     }
 }
 
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index 93f45985a7c..e51030eedf8 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -979,8 +979,8 @@ impl<E: Encoder> Encodable<E> for Span {
 }
 impl<D: Decoder> Decodable<D> for Span {
     default fn decode(s: &mut D) -> Span {
-        let lo = s.read_struct_field("lo", Decodable::decode);
-        let hi = s.read_struct_field("hi", Decodable::decode);
+        let lo = Decodable::decode(s);
+        let hi = Decodable::decode(s);
 
         Span::new(lo, hi, SyntaxContext::root(), None)
     }
@@ -1438,11 +1438,11 @@ impl<S: Encoder> Encodable<S> for SourceFile {
 
 impl<D: Decoder> Decodable<D> for SourceFile {
     fn decode(d: &mut D) -> SourceFile {
-        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 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| {
+        let name: FileName = Decodable::decode(d);
+        let src_hash: SourceFileHash = Decodable::decode(d);
+        let start_pos: BytePos = Decodable::decode(d);
+        let end_pos: BytePos = Decodable::decode(d);
+        let lines: Vec<BytePos> = {
             let num_lines: u32 = Decodable::decode(d);
             let mut lines = Vec::with_capacity(num_lines as usize);
 
@@ -1469,15 +1469,12 @@ impl<D: Decoder> Decodable<D> for SourceFile {
             }
 
             lines
-        });
-        let multibyte_chars: Vec<MultiByteChar> =
-            d.read_struct_field("multibyte_chars", |d| Decodable::decode(d));
-        let non_narrow_chars: Vec<NonNarrowChar> =
-            d.read_struct_field("non_narrow_chars", |d| Decodable::decode(d));
-        let name_hash: u128 = d.read_struct_field("name_hash", |d| Decodable::decode(d));
-        let normalized_pos: Vec<NormalizedPos> =
-            d.read_struct_field("normalized_pos", |d| Decodable::decode(d));
-        let cnum: CrateNum = d.read_struct_field("cnum", |d| Decodable::decode(d));
+        };
+        let multibyte_chars: Vec<MultiByteChar> = Decodable::decode(d);
+        let non_narrow_chars: Vec<NonNarrowChar> = Decodable::decode(d);
+        let name_hash: u128 = Decodable::decode(d);
+        let normalized_pos: Vec<NormalizedPos> = Decodable::decode(d);
+        let cnum: CrateNum = Decodable::decode(d);
         SourceFile {
             name,
             start_pos,