about summary refs log tree commit diff
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2022-02-09 17:20:43 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2022-02-20 18:58:22 -0500
commitc021ba48a70e69fa681ea6617512ae2028e2677a (patch)
treea559aec34a2ed348bcd169d2a18021812213e1ae /compiler/rustc_span/src
parenta421b631ba0af42878250174e57ee25b8f7dbf03 (diff)
downloadrust-c021ba48a70e69fa681ea6617512ae2028e2677a.tar.gz
rust-c021ba48a70e69fa681ea6617512ae2028e2677a.zip
Delete Decoder::read_struct
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/def_id.rs4
-rw-r--r--compiler/rustc_span/src/lib.rs115
2 files changed, 57 insertions, 62 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs
index 147c1f9e043..5b6f110413a 100644
--- a/compiler/rustc_span/src/def_id.rs
+++ b/compiler/rustc_span/src/def_id.rs
@@ -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),
-        })
+        }
     }
 }
 
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index 5991b4d217c..93f45985a7c 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -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)
-        })
+        Span::new(lo, hi, SyntaxContext::root(), None)
     }
 }
 
@@ -1440,65 +1438,62 @@ 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 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 num_lines: u32 = Decodable::decode(d);
-                let mut lines = Vec::with_capacity(num_lines as usize);
-
-                if num_lines > 0 {
-                    // Read the number of bytes used per diff.
-                    let bytes_per_diff: u8 = Decodable::decode(d);
-
-                    // Read the first element.
-                    let mut line_start: BytePos = Decodable::decode(d);
-                    lines.push(line_start);
-
-                    for _ in 1..num_lines {
-                        let diff = match bytes_per_diff {
-                            1 => d.read_u8() as u32,
-                            2 => d.read_u16() as u32,
-                            4 => d.read_u32(),
-                            _ => unreachable!(),
-                        };
+        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 num_lines: u32 = Decodable::decode(d);
+            let mut lines = Vec::with_capacity(num_lines as usize);
+
+            if num_lines > 0 {
+                // Read the number of bytes used per diff.
+                let bytes_per_diff: u8 = Decodable::decode(d);
+
+                // Read the first element.
+                let mut line_start: BytePos = Decodable::decode(d);
+                lines.push(line_start);
+
+                for _ in 1..num_lines {
+                    let diff = match bytes_per_diff {
+                        1 => d.read_u8() as u32,
+                        2 => d.read_u16() as u32,
+                        4 => d.read_u32(),
+                        _ => unreachable!(),
+                    };
 
-                        line_start = line_start + BytePos(diff);
+                    line_start = line_start + BytePos(diff);
 
-                        lines.push(line_start);
-                    }
+                    lines.push(line_start);
                 }
-
-                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));
-            SourceFile {
-                name,
-                start_pos,
-                end_pos,
-                src: None,
-                src_hash,
-                // Unused - the metadata decoder will construct
-                // a new SourceFile, filling in `external_src` properly
-                external_src: Lock::new(ExternalSource::Unneeded),
-                lines,
-                multibyte_chars,
-                non_narrow_chars,
-                normalized_pos,
-                name_hash,
-                cnum,
             }
-        })
+
+            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));
+        SourceFile {
+            name,
+            start_pos,
+            end_pos,
+            src: None,
+            src_hash,
+            // Unused - the metadata decoder will construct
+            // a new SourceFile, filling in `external_src` properly
+            external_src: Lock::new(ExternalSource::Unneeded),
+            lines,
+            multibyte_chars,
+            non_narrow_chars,
+            normalized_pos,
+            name_hash,
+            cnum,
+        }
     }
 }