about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-03-15 15:06:47 -0700
committerbors <bors@rust-lang.org>2013-03-15 15:06:47 -0700
commite75a843efa66fbcbe7db8473c3ee8f26fa2230ff (patch)
tree5a8fabd2a9d064f4231b26e653fb9de9bdc3470b /src/libsyntax
parent2b059c6e5638de7b241ffddb38cef906813de245 (diff)
parent4bd26481c4c91858c544981990efb2f48e5d3bbe (diff)
downloadrust-e75a843efa66fbcbe7db8473c3ee8f26fa2230ff.tar.gz
rust-e75a843efa66fbcbe7db8473c3ee8f26fa2230ff.zip
auto merge of #5357 : jbclements/rust/add-nonempty-span-encoding, r=jbclements
r? @nikomatsakis 
r? @erickt 

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.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/codemap.rs2
-rw-r--r--src/libsyntax/parse/mod.rs27
2 files changed, 14 insertions, 15 deletions
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<S:Encoder> Encodable<S> for span {
     /* Note #1972 -- spans are encoded but not decoded */
-    fn encode(&self, _s: &S) { }
+    fn encode(&self, _s: &S) { _s.emit_nil() }
 }
 
 impl<D:Decoder> Decodable<D> for span {
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 1cdf485d404..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<std::json::Encoder>) -> ~str {
+    #[test] fn to_json_str<E : Encodable<std::json::Encoder>>(val: @E) -> ~str {
         do io::with_str_writer |writer| {
             val.encode(~std::json::Encoder(writer));
         }
@@ -312,18 +311,18 @@ mod test {
             @~"fn foo (x : int) { x; }",
             ~[],
             new_parse_sess(None));
-        check_equal(to_json_str(@tts as @Encodable<std::json::Encoder>),
-                    ~"[[\"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),
+                    ~"[[\"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(~[]);