diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index aac5339a540..eeab4a85c82 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -104,7 +104,7 @@ fn load_pkg(filename: str) -> option::t { let sess = @{ cm: cm, mutable next_id: 0, - diagnostic: diagnostic::mk_codemap_handler(cm) + diagnostic: diagnostic::mk_codemap_handler(cm, none) }; let c = parser::parse_crate_from_crate_file(filename, [], sess); diff --git a/src/comp/driver/diagnostic.rs b/src/comp/driver/diagnostic.rs index e1c360daf12..58c357d724d 100644 --- a/src/comp/driver/diagnostic.rs +++ b/src/comp/driver/diagnostic.rs @@ -3,10 +3,14 @@ import syntax::codemap; import codemap::span; -export emit_diagnostic; +export emitter, emit_diagnostic; export diagnostictype, fatal, error, warning, note; export handler, mk_codemap_handler; +type emitter = fn@(cmsp: option<(codemap::codemap, span)>, + msg: str, t: diagnostictype); + + iface handler { fn span_fatal(sp: span, msg: str) -> !; fn fatal(msg: str) -> !; @@ -26,24 +30,25 @@ type codemap_t = @{ cm: codemap::codemap, - mutable err_count: uint + mutable err_count: uint, + emit: emitter }; impl codemap_handler of handler for codemap_t { fn span_fatal(sp: span, msg: str) -> ! { - emit_diagnostic(some((self.cm, sp)), msg, fatal); + self.emit(some((self.cm, sp)), msg, fatal); fail; } fn fatal(msg: str) -> ! { - emit_diagnostic(none, msg, fatal); + self.emit(none, msg, fatal); fail; } fn span_err(sp: span, msg: str) { - emit_diagnostic(some((self.cm, sp)), msg, error); + self.emit(some((self.cm, sp)), msg, error); self.err_count += 1u; } fn err(msg: str) { - emit_diagnostic(none, msg, error); + self.emit(none, msg, error); self.err_count += 1u; } fn has_errors() -> bool { self.err_count > 0u } @@ -53,16 +58,16 @@ fn abort_if_errors() { } } fn span_warn(sp: span, msg: str) { - emit_diagnostic(some((self.cm, sp)), msg, warning); + self.emit(some((self.cm, sp)), msg, warning); } fn warn(msg: str) { - emit_diagnostic(none, msg, warning); + self.emit(none, msg, warning); } fn span_note(sp: span, msg: str) { - emit_diagnostic(some((self.cm, sp)), msg, note); + self.emit(some((self.cm, sp)), msg, note); } fn note(msg: str) { - emit_diagnostic(none, msg, note); + self.emit(none, msg, note); } fn span_bug(sp: span, msg: str) -> ! { self.span_fatal(sp, #fmt["internal compiler error %s", msg]); @@ -76,10 +81,24 @@ fn span_unimpl(sp: span, msg: str) -> ! { fn unimpl(msg: str) -> ! { self.bug("unimplemented " + msg); } } -fn mk_codemap_handler(cm: codemap::codemap) -> handler { +fn mk_codemap_handler(cm: codemap::codemap, + emitter: option) -> handler { + + let emit = alt emitter { + some(e) { e } + none. { + let f = fn@(cmsp: option<(codemap::codemap, span)>, + msg: str, t: diagnostictype) { + emit_diagnostic(cmsp, msg, t); + }; + f + } + }; + @{ cm: cm, mutable err_count: 0u, + emit: emit } as handler } diff --git a/src/comp/driver/driver.rs b/src/comp/driver/driver.rs index 278ffb9b605..6a578a3f0cf 100644 --- a/src/comp/driver/driver.rs +++ b/src/comp/driver/driver.rs @@ -452,7 +452,7 @@ fn build_session(sopts: @session::options, input: str) -> session::session { sopts.target_triple, sopts.addl_lib_search_paths); let codemap = codemap::new_codemap(); - let diagnostic_handler = diagnostic::mk_codemap_handler(codemap); + let diagnostic_handler = diagnostic::mk_codemap_handler(codemap, none); @{targ_cfg: target_cfg, opts: sopts, cstore: cstore, diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 9800032ed98..343035fe681 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -262,7 +262,7 @@ fn check_variants_T( let str3 = as_str(bind pprust::print_crate( codemap, - diagnostic::mk_codemap_handler(codemap), + diagnostic::mk_codemap_handler(codemap, none), crate2, filename, io::string_reader(""), _, @@ -419,7 +419,7 @@ fn parse_and_print(code: str) -> str { let sess = @{ cm: cm, mutable next_id: 0, - diagnostic: diagnostic::mk_codemap_handler(cm) + diagnostic: diagnostic::mk_codemap_handler(cm, none) }; write_file(filename, code); let crate = parser::parse_crate_from_source_str( @@ -566,7 +566,7 @@ fn check_variants(files: [str], cx: context) { let sess = @{ cm: cm, mutable next_id: 0, - diagnostic: diagnostic::mk_codemap_handler(cm) + diagnostic: diagnostic::mk_codemap_handler(cm, none) }; let crate = parser::parse_crate_from_source_str( diff --git a/src/rustdoc/rustdoc.rs b/src/rustdoc/rustdoc.rs index d743eafcbca..733b1fecc0e 100755 --- a/src/rustdoc/rustdoc.rs +++ b/src/rustdoc/rustdoc.rs @@ -194,7 +194,7 @@ fn main(argv: [str]) { let sess = @{ cm: cm, mutable next_id: 0, - diagnostic: diagnostic::mk_codemap_handler(cm) + diagnostic: diagnostic::mk_codemap_handler(cm, none) }; let rd = { ps: pprust::rust_printer(w), w: w }; doc_header(rd, argv[1]);