about summary refs log tree commit diff
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2012-06-11 08:32:38 -0700
committerGraydon Hoare <graydon@mozilla.com>2012-06-12 18:10:18 -0700
commita816176eb56bd87552b73069bcb6c2dd69ce7d69 (patch)
tree49961946e45c89b54e39817ece7d66cd7ffc8c43
parentac4ac328ee1b2c90194a17eab9b30b23112e4d95 (diff)
downloadrust-a816176eb56bd87552b73069bcb6c2dd69ce7d69.tar.gz
rust-a816176eb56bd87552b73069bcb6c2dd69ce7d69.zip
std: Add a to_str impl for json::error.
-rw-r--r--src/cargo/cargo.rs7
-rw-r--r--src/libstd/json.rs6
2 files changed, 10 insertions, 3 deletions
diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs
index 1c9ae6f866a..533ecf51e01 100644
--- a/src/cargo/cargo.rs
+++ b/src/cargo/cargo.rs
@@ -12,6 +12,7 @@ import io::writer_util;
 import result;
 import std::{map, json, tempfile, term, sort, getopts};
 import map::hashmap;
+import json::to_str;
 import str;
 import vec;
 import getopts::{optflag, optopt, opt_present};
@@ -450,7 +451,7 @@ fn try_parse_sources(filename: str, sources: map::hashmap<str, source>) {
             }
         }
         ok(_) { fail "malformed sources.json"; }
-        err(e) { fail #fmt("%s:%u:%u: %s", filename, e.line, e.col, e.msg); }
+        err(e) { fail #fmt("%s:%s", filename, e.to_str()); }
     }
 }
 
@@ -570,7 +571,7 @@ fn load_source_info(c: cargo, src: source) {
                  "(source info is not a dict)");
         }
         err(e) {
-            warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg));
+            warn(#fmt("%s:%s", src.name, e.to_str()));
         }
     };
 }
@@ -599,7 +600,7 @@ fn load_source_packages(c: cargo, src: source) {
                  "(packages is not a list)");
         }
         err(e) {
-            warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg));
+            warn(#fmt("%s:%s", src.name, e.to_str()));
         }
     };
 }
diff --git a/src/libstd/json.rs b/src/libstd/json.rs
index 5d9427c72b8..1ccdc5042dd 100644
--- a/src/libstd/json.rs
+++ b/src/libstd/json.rs
@@ -603,6 +603,12 @@ impl of to_str::to_str for json {
     fn to_str() -> str { to_str(self) }
 }
 
+impl of to_str::to_str for error {
+    fn to_str() -> str {
+        #fmt("%u:%u: %s", self.line, self.col, self.msg)
+    }
+}
+
 #[cfg(test)]
 mod tests {
     fn mk_dict(items: [(str, json)]) -> json {