diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2016-01-20 10:04:31 -0800 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2016-01-20 10:04:31 -0800 |
| commit | 1dc7eb8853f3ff5d8e4f7e4a717c55a7073f5533 (patch) | |
| tree | 927a01951a4f496ebd5028db75499fd08bd67879 /src/libsyntax/codemap.rs | |
| parent | c4c9628de7d4e970b2cb43d0f1a4c8f9ad03aca1 (diff) | |
syntax: Fix encoding and decoding spans
The protocol for `serialize::{En,De}code` doesn't allow for two
integers to be serialized next to each other. This switches the
protocol to serializing `Span`s as a struct. rbml structs don't
have any overhead, so the metadata shouldn't increase in size,
but it allows the json format to be properly generated, albeit
slightly more heavy than when it was just serializing a span as
a u64.
Closes #31025.
s
Diffstat (limited to 'src/libsyntax/codemap.rs')
| -rw-r--r-- | src/libsyntax/codemap.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 19236f2cd98..8d6c0df981f 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -164,16 +164,31 @@ impl Eq for Span {} impl Encodable for Span { fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - try!(s.emit_u32(self.lo.0)); - s.emit_u32(self.hi.0) + s.emit_struct("Span", 2, |s| { + try!(s.emit_struct_field("lo", 0, |s| { + self.lo.encode(s) + })); + + s.emit_struct_field("hi", 1, |s| { + self.hi.encode(s) + }) + }) } } impl Decodable for Span { fn decode<D: Decoder>(d: &mut D) -> Result<Span, D::Error> { - let lo = BytePos(try! { d.read_u32() }); - let hi = BytePos(try! { d.read_u32() }); - Ok(mk_sp(lo, hi)) + d.read_struct("Span", 2, |d| { + let lo = try!(d.read_struct_field("lo", 0, |d| { + BytePos::decode(d) + })); + + let hi = try!(d.read_struct_field("hi", 1, |d| { + BytePos::decode(d) + })); + + Ok(mk_sp(lo, hi)) + }) } } |
