Skip to content

Commit e502492

Browse files
committed
Make fatal errors more consistent.
1 parent 329e487 commit e502492

File tree

7 files changed

+23
-27
lines changed

7 files changed

+23
-27
lines changed

src/librustc/session/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -657,15 +657,15 @@ pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
657657
let target = match Target::search(&opts.target_triple) {
658658
Ok(t) => t,
659659
Err(e) => {
660-
sp.handler().fatal(&format!("Error loading target specification: {}", e));
660+
panic!(sp.handler().fatal(&format!("Error loading target specification: {}", e)));
661661
}
662662
};
663663

664664
let (int_type, uint_type) = match &target.target_pointer_width[..] {
665665
"32" => (ast::TyI32, ast::TyU32),
666666
"64" => (ast::TyI64, ast::TyU64),
667-
w => sp.handler().fatal(&format!("target specification was invalid: unrecognized \
668-
target-pointer-width {}", w))
667+
w => panic!(sp.handler().fatal(&format!("target specification was invalid: \
668+
unrecognized target-pointer-width {}", w))),
669669
};
670670

671671
Config {

src/librustc/session/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Session {
9494
if self.opts.treat_err_as_bug {
9595
self.bug(msg);
9696
}
97-
self.diagnostic().handler().fatal(msg)
97+
panic!(self.diagnostic().handler().fatal(msg))
9898
}
9999
pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) {
100100
if is_warning {
@@ -415,8 +415,8 @@ pub fn build_session_(sopts: config::Options,
415415
let host = match Target::search(config::host_triple()) {
416416
Ok(t) => t,
417417
Err(e) => {
418-
span_diagnostic.handler()
419-
.fatal(&format!("Error loading host specification: {}", e));
418+
panic!(span_diagnostic.handler()
419+
.fatal(&format!("Error loading host specification: {}", e)));
420420
}
421421
};
422422
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);

src/librustc_back/target/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ impl Target {
257257
.map(|s| s.as_string())
258258
.and_then(|os| os.map(|s| s.to_string())) {
259259
Some(val) => val,
260-
None =>
261-
handler.fatal(&format!("Field {} in target specification is required", name))
260+
None => {
261+
panic!(handler.fatal(&format!("Field {} in target specification is required",
262+
name)))
263+
}
262264
}
263265
};
264266

src/librustc_trans/back/write.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! {
3838
unsafe {
3939
let cstr = llvm::LLVMRustGetLastError();
4040
if cstr == ptr::null() {
41-
handler.fatal(&msg[..]);
41+
panic!(handler.fatal(&msg[..]));
4242
} else {
4343
let err = CStr::from_ptr(cstr).to_bytes();
4444
let err = String::from_utf8_lossy(err).to_string();
4545
libc::free(cstr as *mut _);
46-
handler.fatal(&format!("{}: {}",
47-
&msg[..],
48-
&err[..]));
46+
panic!(handler.fatal(&format!("{}: {}", &msg[..], &err[..])));
4947
}
5048
}
5149
}

src/libsyntax/diagnostic.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,9 @@ impl Handler {
206206
can_emit_warnings: can_emit_warnings
207207
}
208208
}
209-
pub fn fatal(&self, msg: &str) -> ! {
209+
pub fn fatal(&self, msg: &str) -> FatalError {
210210
self.emit.borrow_mut().emit(None, msg, None, Fatal);
211-
212-
// Suppress the fatal error message from the panic below as we've
213-
// already terminated in our own "legitimate" fashion.
214-
io::set_panic(Box::new(io::sink()));
215-
panic!(FatalError);
211+
FatalError
216212
}
217213
pub fn err(&self, msg: &str) {
218214
self.emit.borrow_mut().emit(None, msg, None, Error);
@@ -230,14 +226,15 @@ impl Handler {
230226
pub fn abort_if_errors(&self) {
231227
let s;
232228
match self.err_count.get() {
233-
0 => return,
234-
1 => s = "aborting due to previous error".to_string(),
235-
_ => {
236-
s = format!("aborting due to {} previous errors",
237-
self.err_count.get());
238-
}
229+
0 => return,
230+
1 => s = "aborting due to previous error".to_string(),
231+
_ => {
232+
s = format!("aborting due to {} previous errors",
233+
self.err_count.get());
234+
}
239235
}
240-
self.fatal(&s[..]);
236+
237+
panic!(self.fatal(&s[..]));
241238
}
242239
pub fn warn(&self, msg: &str) {
243240
self.emit.borrow_mut().emit(None, msg, None, Warning);

src/libsyntax/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#![feature(filling_drop)]
3131
#![feature(libc)]
3232
#![feature(rustc_private)]
33-
#![feature(set_stdio)]
3433
#![feature(staged_api)]
3534
#![feature(str_char)]
3635
#![feature(str_escape)]

src/libsyntax/parse/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
235235
let msg = format!("couldn't read {:?}: {}", path.display(), e);
236236
match spanopt {
237237
Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, &msg)),
238-
None => sess.span_diagnostic.handler().fatal(&msg)
238+
None => panic!(sess.span_diagnostic.handler().fatal(&msg))
239239
}
240240
}
241241
}

0 commit comments

Comments
 (0)