Skip to content

Commit 97e0575

Browse files
committed
Add a span_str function in session
1 parent 79693fa commit 97e0575

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/comp/driver/session.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ type options = rec(bool shared,
4141
type crate_metadata = rec(str name,
4242
vec[u8] data);
4343

44-
fn emit_diagnostic(span sp, str msg, str kind, u8 color,
45-
codemap::codemap cm) {
44+
fn span_to_str(span sp, codemap::codemap cm) -> str {
4645
auto lo = codemap::lookup_pos(cm, sp.lo);
4746
auto hi = codemap::lookup_pos(cm, sp.hi);
48-
io::stdout().write_str(#fmt("%s:%u:%u:%u:%u: ", lo.filename, lo.line,
49-
lo.col, hi.line, hi.col));
47+
ret (#fmt("%s:%u:%u:%u:%u", lo.filename, lo.line,
48+
lo.col, hi.line, hi.col));
49+
}
50+
51+
fn emit_diagnostic(span sp, str msg, str kind, u8 color,
52+
codemap::codemap cm) {
53+
io::stdout().write_str(span_to_str(sp, cm) + ": ");
5054

5155
if (term::color_supported()) {
5256
term::fg(io::stdout().get_buf_writer(), color);
@@ -143,6 +147,10 @@ state obj session(ast::crate_num cnum,
143147
fn lookup_pos(uint pos) -> codemap::loc {
144148
ret codemap::lookup_pos(cm, pos);
145149
}
150+
151+
fn span_str(span sp) -> str {
152+
ret span_to_str(sp, self.get_codemap());
153+
}
146154
}
147155

148156

0 commit comments

Comments
 (0)