From 31e09f740a376a6ffd1b137e665a69f9b9436e1f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 18 Feb 2015 11:02:06 -0500 Subject: [PATCH] Add handy switch `-Z treat-err-as-bug` -- it often happens that I am compiling something I expect to succeed, and this lets me get stacktraces and also abort compilation faster. --- src/librustc/session/config.rs | 6 ++++++ src/librustc/session/mod.rs | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index efc12d00b10..efcde8b2fa1 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -99,6 +99,7 @@ pub struct Options { pub test: bool, pub parse_only: bool, pub no_trans: bool, + pub treat_err_as_bug: bool, pub no_analysis: bool, pub debugging_opts: DebuggingOptions, /// Whether to write dependency files. It's (enabled, optional filename). @@ -223,6 +224,7 @@ pub fn basic_options() -> Options { test: false, parse_only: false, no_trans: false, + treat_err_as_bug: false, no_analysis: false, debugging_opts: basic_debugging_options(), write_dependency_info: (false, None), @@ -573,6 +575,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "Parse only; do not compile, assemble, or link"), no_trans: bool = (false, parse_bool, "Run all passes except translation; no output"), + treat_err_as_bug: bool = (false, parse_bool, + "Treat all errors that occur as bugs"), no_analysis: bool = (false, parse_bool, "Parse and expand the source, but run no analysis"), extra_plugins: Vec = (Vec::new(), parse_list, @@ -843,6 +847,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let parse_only = debugging_opts.parse_only; let no_trans = debugging_opts.no_trans; + let treat_err_as_bug = debugging_opts.treat_err_as_bug; let no_analysis = debugging_opts.no_analysis; if debugging_opts.debug_llvm { @@ -1030,6 +1035,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { test: test, parse_only: parse_only, no_trans: no_trans, + treat_err_as_bug: treat_err_as_bug, no_analysis: no_analysis, debugging_opts: debugging_opts, write_dependency_info: write_dependency_info, diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index b690cc7f7d0..324ce1d66d0 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -74,18 +74,27 @@ impl Session { self.diagnostic().handler().fatal(msg) } pub fn span_err(&self, sp: Span, msg: &str) { + if self.opts.treat_err_as_bug { + self.span_bug(sp, msg); + } match split_msg_into_multilines(msg) { Some(msg) => self.diagnostic().span_err(sp, &msg[..]), None => self.diagnostic().span_err(sp, msg) } } pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) { + if self.opts.treat_err_as_bug { + self.span_bug(sp, msg); + } match split_msg_into_multilines(msg) { Some(msg) => self.diagnostic().span_err_with_code(sp, &msg[..], code), None => self.diagnostic().span_err_with_code(sp, msg, code) } } pub fn err(&self, msg: &str) { + if self.opts.treat_err_as_bug { + self.bug(msg); + } self.diagnostic().handler().err(msg) } pub fn err_count(&self) -> uint {