diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2019-08-24 16:25:55 +0100 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2019-08-27 23:02:22 +0100 |
| commit | 3d718037dcddd2aa56bd2727dee074ac9b6a6f0e (patch) | |
| tree | ca95b9980825f513fb9324434dd0cd19f39f4363 /src/libsyntax_pos | |
| parent | 0396aace27eea97c3603e9683e921807dff2a314 (diff) | |
Add default serialization for `Ident`s
Add tests for -Zast-json and -Zast-json-noexpand, which need this impl.
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/symbol.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 0b8f16bbc3b..2d8e97c1800 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -849,9 +849,29 @@ impl fmt::Display for Ident { } } -impl UseSpecializedEncodable for Ident {} +impl UseSpecializedEncodable for Ident { + fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { + s.emit_struct("Ident", 2, |s| { + s.emit_struct_field("name", 0, |s| { + self.name.encode(s) + })?; + s.emit_struct_field("span", 1, |s| { + self.span.encode(s) + }) + }) + } +} -impl UseSpecializedDecodable for Ident {} +impl UseSpecializedDecodable for Ident { + fn default_decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> { + d.read_struct("Ident", 2, |d| { + Ok(Ident { + name: d.read_struct_field("name", 0, Decodable::decode)?, + span: d.read_struct_field("span", 1, Decodable::decode)?, + }) + }) + } +} /// A symbol is an interned or gensymed string. A gensym is a symbol that is /// never equal to any other symbol. |
