diff --git a/src/librustsyntax/diagnostic.rs b/src/librustsyntax/diagnostic.rs index 184c32f2146..64904d612ce 100644 --- a/src/librustsyntax/diagnostic.rs +++ b/src/librustsyntax/diagnostic.rs @@ -7,6 +7,7 @@ export span_handler, handler, mk_span_handler, mk_handler; export codemap_span_handler, codemap_handler; export ice_msg; +export expect; type emitter = fn@(cmsp: option<(codemap::codemap, span)>, msg: str, lvl: level); @@ -253,3 +254,11 @@ fn print_macro_backtrace(cm: codemap::codemap, sp: span) { print_macro_backtrace(cm, ei.call_site); } } + +fn expect(diag: span_handler, + opt: option, msg: fn() -> str) -> T { + alt opt { + some(t) { t } + none { diag.handler().bug(msg()); } + } +} diff --git a/src/rustc/driver/session.rs b/src/rustc/driver/session.rs index ea815d9e410..deecce66b30 100644 --- a/src/rustc/driver/session.rs +++ b/src/rustc/driver/session.rs @@ -171,10 +171,7 @@ fn basic_options() -> @options { // Seems out of place, but it uses session, so I'm putting it here fn expect(sess: session, opt: option, msg: fn() -> str) -> T { - alt opt { - some(t) { t } - none { sess.bug(msg()); } - } + diagnostic::expect(sess.diagnostic(), opt, msg) } fn building_library(req_crate_type: crate_type, crate: @ast::crate,