syntax: Add diagnostic::expect

This commit is contained in:
Brian Anderson 2012-05-22 14:55:39 -07:00
parent a32392d032
commit 99c1b2953d
2 changed files with 10 additions and 4 deletions

View File

@ -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<T: copy>(diag: span_handler,
opt: option<T>, msg: fn() -> str) -> T {
alt opt {
some(t) { t }
none { diag.handler().bug(msg()); }
}
}

View File

@ -171,10 +171,7 @@ fn basic_options() -> @options {
// Seems out of place, but it uses session, so I'm putting it here
fn expect<T: copy>(sess: session, opt: option<T>, 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,