Make fatal errors more consistent.
This commit is contained in:
parent
329e487e58
commit
e5024924ad
@ -657,15 +657,15 @@ pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
|
||||
let target = match Target::search(&opts.target_triple) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
sp.handler().fatal(&format!("Error loading target specification: {}", e));
|
||||
panic!(sp.handler().fatal(&format!("Error loading target specification: {}", e)));
|
||||
}
|
||||
};
|
||||
|
||||
let (int_type, uint_type) = match &target.target_pointer_width[..] {
|
||||
"32" => (ast::TyI32, ast::TyU32),
|
||||
"64" => (ast::TyI64, ast::TyU64),
|
||||
w => sp.handler().fatal(&format!("target specification was invalid: unrecognized \
|
||||
target-pointer-width {}", w))
|
||||
w => panic!(sp.handler().fatal(&format!("target specification was invalid: \
|
||||
unrecognized target-pointer-width {}", w))),
|
||||
};
|
||||
|
||||
Config {
|
||||
|
@ -94,7 +94,7 @@ impl Session {
|
||||
if self.opts.treat_err_as_bug {
|
||||
self.bug(msg);
|
||||
}
|
||||
self.diagnostic().handler().fatal(msg)
|
||||
panic!(self.diagnostic().handler().fatal(msg))
|
||||
}
|
||||
pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) {
|
||||
if is_warning {
|
||||
@ -415,8 +415,8 @@ pub fn build_session_(sopts: config::Options,
|
||||
let host = match Target::search(config::host_triple()) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
span_diagnostic.handler()
|
||||
.fatal(&format!("Error loading host specification: {}", e));
|
||||
panic!(span_diagnostic.handler()
|
||||
.fatal(&format!("Error loading host specification: {}", e)));
|
||||
}
|
||||
};
|
||||
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
|
||||
|
@ -257,8 +257,10 @@ impl Target {
|
||||
.map(|s| s.as_string())
|
||||
.and_then(|os| os.map(|s| s.to_string())) {
|
||||
Some(val) => val,
|
||||
None =>
|
||||
handler.fatal(&format!("Field {} in target specification is required", name))
|
||||
None => {
|
||||
panic!(handler.fatal(&format!("Field {} in target specification is required",
|
||||
name)))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -38,14 +38,12 @@ pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! {
|
||||
unsafe {
|
||||
let cstr = llvm::LLVMRustGetLastError();
|
||||
if cstr == ptr::null() {
|
||||
handler.fatal(&msg[..]);
|
||||
panic!(handler.fatal(&msg[..]));
|
||||
} else {
|
||||
let err = CStr::from_ptr(cstr).to_bytes();
|
||||
let err = String::from_utf8_lossy(err).to_string();
|
||||
libc::free(cstr as *mut _);
|
||||
handler.fatal(&format!("{}: {}",
|
||||
&msg[..],
|
||||
&err[..]));
|
||||
panic!(handler.fatal(&format!("{}: {}", &msg[..], &err[..])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -206,13 +206,9 @@ impl Handler {
|
||||
can_emit_warnings: can_emit_warnings
|
||||
}
|
||||
}
|
||||
pub fn fatal(&self, msg: &str) -> ! {
|
||||
pub fn fatal(&self, msg: &str) -> FatalError {
|
||||
self.emit.borrow_mut().emit(None, msg, None, Fatal);
|
||||
|
||||
// Suppress the fatal error message from the panic below as we've
|
||||
// already terminated in our own "legitimate" fashion.
|
||||
io::set_panic(Box::new(io::sink()));
|
||||
panic!(FatalError);
|
||||
FatalError
|
||||
}
|
||||
pub fn err(&self, msg: &str) {
|
||||
self.emit.borrow_mut().emit(None, msg, None, Error);
|
||||
@ -230,14 +226,15 @@ impl Handler {
|
||||
pub fn abort_if_errors(&self) {
|
||||
let s;
|
||||
match self.err_count.get() {
|
||||
0 => return,
|
||||
1 => s = "aborting due to previous error".to_string(),
|
||||
_ => {
|
||||
s = format!("aborting due to {} previous errors",
|
||||
self.err_count.get());
|
||||
}
|
||||
0 => return,
|
||||
1 => s = "aborting due to previous error".to_string(),
|
||||
_ => {
|
||||
s = format!("aborting due to {} previous errors",
|
||||
self.err_count.get());
|
||||
}
|
||||
}
|
||||
self.fatal(&s[..]);
|
||||
|
||||
panic!(self.fatal(&s[..]));
|
||||
}
|
||||
pub fn warn(&self, msg: &str) {
|
||||
self.emit.borrow_mut().emit(None, msg, None, Warning);
|
||||
|
@ -30,7 +30,6 @@
|
||||
#![feature(filling_drop)]
|
||||
#![feature(libc)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(set_stdio)]
|
||||
#![feature(staged_api)]
|
||||
#![feature(str_char)]
|
||||
#![feature(str_escape)]
|
||||
|
@ -235,7 +235,7 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
|
||||
let msg = format!("couldn't read {:?}: {}", path.display(), e);
|
||||
match spanopt {
|
||||
Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, &msg)),
|
||||
None => sess.span_diagnostic.handler().fatal(&msg)
|
||||
None => panic!(sess.span_diagnostic.handler().fatal(&msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user