Skip to content

Commit a816176

Browse files
ericktgraydon
authored andcommitted
std: Add a to_str impl for json::error.
1 parent ac4ac32 commit a816176

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/cargo/cargo.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io::writer_util;
1212
import result;
1313
import std::{map, json, tempfile, term, sort, getopts};
1414
import map::hashmap;
15+
import json::to_str;
1516
import str;
1617
import vec;
1718
import getopts::{optflag, optopt, opt_present};
@@ -450,7 +451,7 @@ fn try_parse_sources(filename: str, sources: map::hashmap<str, source>) {
450451
}
451452
}
452453
ok(_) { fail "malformed sources.json"; }
453-
err(e) { fail #fmt("%s:%u:%u: %s", filename, e.line, e.col, e.msg); }
454+
err(e) { fail #fmt("%s:%s", filename, e.to_str()); }
454455
}
455456
}
456457

@@ -570,7 +571,7 @@ fn load_source_info(c: cargo, src: source) {
570571
"(source info is not a dict)");
571572
}
572573
err(e) {
573-
warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg));
574+
warn(#fmt("%s:%s", src.name, e.to_str()));
574575
}
575576
};
576577
}
@@ -599,7 +600,7 @@ fn load_source_packages(c: cargo, src: source) {
599600
"(packages is not a list)");
600601
}
601602
err(e) {
602-
warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg));
603+
warn(#fmt("%s:%s", src.name, e.to_str()));
603604
}
604605
};
605606
}

src/libstd/json.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,12 @@ impl of to_str::to_str for json {
603603
fn to_str() -> str { to_str(self) }
604604
}
605605

606+
impl of to_str::to_str for error {
607+
fn to_str() -> str {
608+
#fmt("%u:%u: %s", self.line, self.col, self.msg)
609+
}
610+
}
611+
606612
#[cfg(test)]
607613
mod tests {
608614
fn mk_dict(items: [(str, json)]) -> json {

0 commit comments

Comments
 (0)