Skip to content

Commit 31e09f7

Browse files
committed
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.
1 parent cf73e36 commit 31e09f7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/librustc/session/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub struct Options {
9999
pub test: bool,
100100
pub parse_only: bool,
101101
pub no_trans: bool,
102+
pub treat_err_as_bug: bool,
102103
pub no_analysis: bool,
103104
pub debugging_opts: DebuggingOptions,
104105
/// Whether to write dependency files. It's (enabled, optional filename).
@@ -223,6 +224,7 @@ pub fn basic_options() -> Options {
223224
test: false,
224225
parse_only: false,
225226
no_trans: false,
227+
treat_err_as_bug: false,
226228
no_analysis: false,
227229
debugging_opts: basic_debugging_options(),
228230
write_dependency_info: (false, None),
@@ -573,6 +575,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
573575
"Parse only; do not compile, assemble, or link"),
574576
no_trans: bool = (false, parse_bool,
575577
"Run all passes except translation; no output"),
578+
treat_err_as_bug: bool = (false, parse_bool,
579+
"Treat all errors that occur as bugs"),
576580
no_analysis: bool = (false, parse_bool,
577581
"Parse and expand the source, but run no analysis"),
578582
extra_plugins: Vec<String> = (Vec::new(), parse_list,
@@ -843,6 +847,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
843847

844848
let parse_only = debugging_opts.parse_only;
845849
let no_trans = debugging_opts.no_trans;
850+
let treat_err_as_bug = debugging_opts.treat_err_as_bug;
846851
let no_analysis = debugging_opts.no_analysis;
847852

848853
if debugging_opts.debug_llvm {
@@ -1030,6 +1035,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10301035
test: test,
10311036
parse_only: parse_only,
10321037
no_trans: no_trans,
1038+
treat_err_as_bug: treat_err_as_bug,
10331039
no_analysis: no_analysis,
10341040
debugging_opts: debugging_opts,
10351041
write_dependency_info: write_dependency_info,

src/librustc/session/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,27 @@ impl Session {
7474
self.diagnostic().handler().fatal(msg)
7575
}
7676
pub fn span_err(&self, sp: Span, msg: &str) {
77+
if self.opts.treat_err_as_bug {
78+
self.span_bug(sp, msg);
79+
}
7780
match split_msg_into_multilines(msg) {
7881
Some(msg) => self.diagnostic().span_err(sp, &msg[..]),
7982
None => self.diagnostic().span_err(sp, msg)
8083
}
8184
}
8285
pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
86+
if self.opts.treat_err_as_bug {
87+
self.span_bug(sp, msg);
88+
}
8389
match split_msg_into_multilines(msg) {
8490
Some(msg) => self.diagnostic().span_err_with_code(sp, &msg[..], code),
8591
None => self.diagnostic().span_err_with_code(sp, msg, code)
8692
}
8793
}
8894
pub fn err(&self, msg: &str) {
95+
if self.opts.treat_err_as_bug {
96+
self.bug(msg);
97+
}
8998
self.diagnostic().handler().err(msg)
9099
}
91100
pub fn err_count(&self) -> uint {

0 commit comments

Comments
 (0)