1
Fork 0

Make fatal errors more consistent.

This commit is contained in:
Eli Friedman 2015-10-23 19:42:42 -07:00
parent 329e487e58
commit e5024924ad
7 changed files with 23 additions and 27 deletions

View file

@ -657,15 +657,15 @@ pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
let target = match Target::search(&opts.target_triple) { let target = match Target::search(&opts.target_triple) {
Ok(t) => t, Ok(t) => t,
Err(e) => { 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[..] { let (int_type, uint_type) = match &target.target_pointer_width[..] {
"32" => (ast::TyI32, ast::TyU32), "32" => (ast::TyI32, ast::TyU32),
"64" => (ast::TyI64, ast::TyU64), "64" => (ast::TyI64, ast::TyU64),
w => sp.handler().fatal(&format!("target specification was invalid: unrecognized \ w => panic!(sp.handler().fatal(&format!("target specification was invalid: \
target-pointer-width {}", w)) unrecognized target-pointer-width {}", w))),
}; };
Config { Config {

View file

@ -94,7 +94,7 @@ impl Session {
if self.opts.treat_err_as_bug { if self.opts.treat_err_as_bug {
self.bug(msg); 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) { pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) {
if is_warning { if is_warning {
@ -415,8 +415,8 @@ pub fn build_session_(sopts: config::Options,
let host = match Target::search(config::host_triple()) { let host = match Target::search(config::host_triple()) {
Ok(t) => t, Ok(t) => t,
Err(e) => { Err(e) => {
span_diagnostic.handler() panic!(span_diagnostic.handler()
.fatal(&format!("Error loading host specification: {}", e)); .fatal(&format!("Error loading host specification: {}", e)));
} }
}; };
let target_cfg = config::build_target_config(&sopts, &span_diagnostic); let target_cfg = config::build_target_config(&sopts, &span_diagnostic);

View file

@ -257,8 +257,10 @@ impl Target {
.map(|s| s.as_string()) .map(|s| s.as_string())
.and_then(|os| os.map(|s| s.to_string())) { .and_then(|os| os.map(|s| s.to_string())) {
Some(val) => val, Some(val) => val,
None => None => {
handler.fatal(&format!("Field {} in target specification is required", name)) panic!(handler.fatal(&format!("Field {} in target specification is required",
name)))
}
} }
}; };

View file

@ -38,14 +38,12 @@ pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! {
unsafe { unsafe {
let cstr = llvm::LLVMRustGetLastError(); let cstr = llvm::LLVMRustGetLastError();
if cstr == ptr::null() { if cstr == ptr::null() {
handler.fatal(&msg[..]); panic!(handler.fatal(&msg[..]));
} else { } else {
let err = CStr::from_ptr(cstr).to_bytes(); let err = CStr::from_ptr(cstr).to_bytes();
let err = String::from_utf8_lossy(err).to_string(); let err = String::from_utf8_lossy(err).to_string();
libc::free(cstr as *mut _); libc::free(cstr as *mut _);
handler.fatal(&format!("{}: {}", panic!(handler.fatal(&format!("{}: {}", &msg[..], &err[..])));
&msg[..],
&err[..]));
} }
} }
} }

View file

@ -206,13 +206,9 @@ impl Handler {
can_emit_warnings: can_emit_warnings 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); self.emit.borrow_mut().emit(None, msg, None, Fatal);
FatalError
// 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);
} }
pub fn err(&self, msg: &str) { pub fn err(&self, msg: &str) {
self.emit.borrow_mut().emit(None, msg, None, Error); self.emit.borrow_mut().emit(None, msg, None, Error);
@ -230,14 +226,15 @@ impl Handler {
pub fn abort_if_errors(&self) { pub fn abort_if_errors(&self) {
let s; let s;
match self.err_count.get() { match self.err_count.get() {
0 => return, 0 => return,
1 => s = "aborting due to previous error".to_string(), 1 => s = "aborting due to previous error".to_string(),
_ => { _ => {
s = format!("aborting due to {} previous errors", s = format!("aborting due to {} previous errors",
self.err_count.get()); self.err_count.get());
} }
} }
self.fatal(&s[..]);
panic!(self.fatal(&s[..]));
} }
pub fn warn(&self, msg: &str) { pub fn warn(&self, msg: &str) {
self.emit.borrow_mut().emit(None, msg, None, Warning); self.emit.borrow_mut().emit(None, msg, None, Warning);

View file

@ -30,7 +30,6 @@
#![feature(filling_drop)] #![feature(filling_drop)]
#![feature(libc)] #![feature(libc)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(set_stdio)]
#![feature(staged_api)] #![feature(staged_api)]
#![feature(str_char)] #![feature(str_char)]
#![feature(str_escape)] #![feature(str_escape)]

View file

@ -235,7 +235,7 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
let msg = format!("couldn't read {:?}: {}", path.display(), e); let msg = format!("couldn't read {:?}: {}", path.display(), e);
match spanopt { match spanopt {
Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, &msg)), 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))
} }
} }
} }