From fdf8543cf61103e56cd86eadd845a65f12eaad54 Mon Sep 17 00:00:00 2001 From: John Clements Date: Wed, 13 Mar 2013 10:52:45 -0700 Subject: [PATCH 1/3] add nonempty encoding for spans Before this change, encoding an object containing a codemap::span using the JSON encodeng produced invalid JSON, for instance: [{"span":,"global":false,"idents":["abc"]}] Since the decoder for codemap::span's ignores its argument, I conjecture that this will not damage decoding, and should improve it for many decoders. --- src/libsyntax/codemap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 0d6ece8ad92..97719a140a6 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -140,7 +140,7 @@ impl cmp::Eq for span { impl Encodable for span { /* Note #1972 -- spans are encoded but not decoded */ - fn encode(&self, _s: &S) { } + fn encode(&self, _s: &S) { _s.emit_nil() } } impl Decodable for span { From b5ace4df455606b5056331fa3f5ea86498dca448 Mon Sep 17 00:00:00 2001 From: John Clements Date: Thu, 14 Mar 2013 14:23:02 -0700 Subject: [PATCH 2/3] Test case fixup (old one tested the old bad behavior). --- src/libsyntax/parse/mod.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 1cdf485d404..05af549732b 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -312,18 +312,18 @@ mod test { @~"fn foo (x : int) { x; }", ~[], new_parse_sess(None)); - check_equal(to_json_str(@tts as @Encodable), - ~"[[\"tt_tok\",[,[\"IDENT\",[\"fn\",false]]]],\ - [\"tt_tok\",[,[\"IDENT\",[\"foo\",false]]]],\ - [\"tt_delim\",[[[\"tt_tok\",[,[\"LPAREN\",[]]]],\ - [\"tt_tok\",[,[\"IDENT\",[\"x\",false]]]],\ - [\"tt_tok\",[,[\"COLON\",[]]]],\ - [\"tt_tok\",[,[\"IDENT\",[\"int\",false]]]],\ - [\"tt_tok\",[,[\"RPAREN\",[]]]]]]],\ - [\"tt_delim\",[[[\"tt_tok\",[,[\"LBRACE\",[]]]],\ - [\"tt_tok\",[,[\"IDENT\",[\"x\",false]]]],\ - [\"tt_tok\",[,[\"SEMI\",[]]]],\ - [\"tt_tok\",[,[\"RBRACE\",[]]]]]]]]" + check_equal(to_json_str(@tts as Encodable::), + ~"[[\"tt_tok\",[null,[\"IDENT\",[\"fn\",false]]]],\ + [\"tt_tok\",[null,[\"IDENT\",[\"foo\",false]]]],\ + [\"tt_delim\",[[[\"tt_tok\",[null,[\"LPAREN\",[]]]],\ + [\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\ + [\"tt_tok\",[null,[\"COLON\",[]]]],\ + [\"tt_tok\",[null,[\"IDENT\",[\"int\",false]]]],\ + [\"tt_tok\",[null,[\"RPAREN\",[]]]]]]],\ + [\"tt_delim\",[[[\"tt_tok\",[null,[\"LBRACE\",[]]]],\ + [\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\ + [\"tt_tok\",[null,[\"SEMI\",[]]]],\ + [\"tt_tok\",[null,[\"RBRACE\",[]]]]]]]]" ); let ast1 = new_parser_from_tts(new_parse_sess(None),~[],tts) .parse_item(~[]); From 4bd26481c4c91858c544981990efb2f48e5d3bbe Mon Sep 17 00:00:00 2001 From: John Clements Date: Fri, 15 Mar 2013 09:17:49 -0700 Subject: [PATCH 3/3] Update test case to conform to new restrictions on casting --- src/libsyntax/parse/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 05af549732b..66a3ae7a2ae 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -297,10 +297,9 @@ mod test { use std; use core::io; use core::option::None; - use core::str; use util::testing::*; - #[test] fn to_json_str (val: @Encodable) -> ~str { + #[test] fn to_json_str>(val: @E) -> ~str { do io::with_str_writer |writer| { val.encode(~std::json::Encoder(writer)); } @@ -312,7 +311,7 @@ mod test { @~"fn foo (x : int) { x; }", ~[], new_parse_sess(None)); - check_equal(to_json_str(@tts as Encodable::), + check_equal(to_json_str(@tts), ~"[[\"tt_tok\",[null,[\"IDENT\",[\"fn\",false]]]],\ [\"tt_tok\",[null,[\"IDENT\",[\"foo\",false]]]],\ [\"tt_delim\",[[[\"tt_tok\",[null,[\"LPAREN\",[]]]],\