Skip to content

Commit 9ae76b3

Browse files
committed
Auto merge of #31028 - erickt:ast-json, r=michaelwoerister
The protocol for `serialize::{En,De}code` doesn't allow for two integers to be serialized next to each other. Closes #31025. cc @michaelwoerister
2 parents c6ba7fe + 1dc7eb8 commit 9ae76b3

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/libsyntax/codemap.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,31 @@ impl Eq for Span {}
164164

165165
impl Encodable for Span {
166166
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
167-
try!(s.emit_u32(self.lo.0));
168-
s.emit_u32(self.hi.0)
167+
s.emit_struct("Span", 2, |s| {
168+
try!(s.emit_struct_field("lo", 0, |s| {
169+
self.lo.encode(s)
170+
}));
171+
172+
s.emit_struct_field("hi", 1, |s| {
173+
self.hi.encode(s)
174+
})
175+
})
169176
}
170177
}
171178

172179
impl Decodable for Span {
173180
fn decode<D: Decoder>(d: &mut D) -> Result<Span, D::Error> {
174-
let lo = BytePos(try! { d.read_u32() });
175-
let hi = BytePos(try! { d.read_u32() });
176-
Ok(mk_sp(lo, hi))
181+
d.read_struct("Span", 2, |d| {
182+
let lo = try!(d.read_struct_field("lo", 0, |d| {
183+
BytePos::decode(d)
184+
}));
185+
186+
let hi = try!(d.read_struct_field("hi", 1, |d| {
187+
BytePos::decode(d)
188+
}));
189+
190+
Ok(mk_sp(lo, hi))
191+
})
177192
}
178193
}
179194

0 commit comments

Comments
 (0)