diff options
| author | Patrick Walton <[email protected]> | 2011-04-28 10:50:54 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-04-28 10:51:12 -0700 |
| commit | 91fe4ae0900c1ef361952a6c8e0647e70598741c (patch) | |
| tree | 7e4211ab5b5909be34b5b9cb2e2c2738dc385f78 /src | |
| parent | stdlib: Use an unsafe cast to speed up the memory writer (diff) | |
| download | rust-91fe4ae0900c1ef361952a6c8e0647e70598741c.tar.xz rust-91fe4ae0900c1ef361952a6c8e0647e70598741c.zip | |
rustc: Joseph and the Amazing Technicolor Error Messages
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/driver/session.rs | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs index 8e0f22b2..9dba5e58 100644 --- a/src/comp/driver/session.rs +++ b/src/comp/driver/session.rs @@ -3,6 +3,8 @@ import front.codemap; import util.common.span; import util.common.ty_mach; import std._uint; +import std.Term; +import std.io; import std.map; tag os { @@ -26,6 +28,17 @@ type cfg = rec(os os, type crate_metadata = rec(str name, vec[u8] data); +fn emit_diagnostic(span sp, str msg, str kind, u8 color, codemap.codemap cm) { + auto lo = codemap.lookup_pos(cm, sp.lo); + auto hi = codemap.lookup_pos(cm, sp.hi); + io.stdout().write_str(#fmt("%s:%u:%u:%u:%u: ", lo.filename, lo.line, + lo.col, hi.line, hi.col)); + Term.fg(io.stdout().get_buf_writer(), color); + io.stdout().write_str(#fmt("%s:", kind)); + Term.reset(io.stdout().get_buf_writer()); + io.stdout().write_str(#fmt(" %s\n", msg)); +} + state obj session(ast.crate_num cnum, cfg targ, map.hashmap[int, crate_metadata] crates, mutable vec[@ast.meta_item] metadata, @@ -40,13 +53,8 @@ state obj session(ast.crate_num cnum, cfg targ, } fn span_err(span sp, str msg) { - auto lo = codemap.lookup_pos(cm, sp.lo); - auto hi = codemap.lookup_pos(cm, sp.hi); - log_err #fmt("%s:%u:%u:%u:%u: error: %s", - lo.filename, - lo.line, lo.col, - hi.line, hi.col, - msg); + // FIXME: Use constants, but rustboot doesn't know how to export them. + emit_diagnostic(sp, msg, "error", 9u8, cm); fail; } @@ -63,13 +71,8 @@ state obj session(ast.crate_num cnum, cfg targ, } fn span_warn(span sp, str msg) { - auto lo = codemap.lookup_pos(cm, sp.lo); - auto hi = codemap.lookup_pos(cm, sp.hi); - log_err #fmt("%s:%u:%u:%u:%u: warning: %s", - lo.filename, - lo.line, lo.col, - hi.line, hi.col, - msg); + // FIXME: Use constants, but rustboot doesn't know how to export them. + emit_diagnostic(sp, msg, "warning", 11u8, cm); } fn bug(str msg) { @@ -78,13 +81,9 @@ state obj session(ast.crate_num cnum, cfg targ, } fn span_unimpl(span sp, str msg) { - auto lo = codemap.lookup_pos(cm, sp.lo); - auto hi = codemap.lookup_pos(cm, sp.hi); - log_err #fmt("%s:%u:%u:%u:%u: error: unimplemented %s", - lo.filename, - lo.line, lo.col, - hi.line, hi.col, - msg); + // FIXME: Use constants, but rustboot doesn't know how to export them. + emit_diagnostic(sp, "internal compiler error: unimplemented " + msg, + "error", 9u8, cm); fail; } |