syntax: Add diagnostic::expect
This commit is contained in:
parent
a32392d032
commit
99c1b2953d
@ -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()); }
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user