Skip to content

Commit

Permalink
Keep current behavior while accepting error count
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 7, 2019
1 parent 754037d commit c41ddf1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,8 @@ macro_rules! options {
Some("crate=integer");
pub const parse_unpretty: Option<&str> =
Some("`string` or `string=string`");
pub const parse_treat_err_as_bug: Option<&str> =
Some("either no value or a number bigger than 0");
pub const parse_lto: Option<&str> =
Some("either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \
`fat`, or omitted");
Expand Down Expand Up @@ -1022,6 +1024,13 @@ macro_rules! options {
}
}

fn parse_treat_err_as_bug(slot: &mut Option<usize>, v: Option<&str>) -> bool {
match v {
Some(s) => { *slot = s.parse().ok().filter(|&x| x != 0); slot.unwrap_or(0) != 0 }
None => { *slot = Some(1); true }
}
}

fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
if v.is_some() {
let mut bool_arg = None;
Expand Down Expand Up @@ -1234,7 +1243,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"parse only; do not compile, assemble, or link"),
no_codegen: bool = (false, parse_bool, [TRACKED],
"run all passes except codegen; no output"),
treat_err_as_bug: Option<usize> = (None, parse_opt_uint, [TRACKED],
treat_err_as_bug: Option<usize> = (None, parse_treat_err_as_bug, [TRACKED],
"treat all errors that occur as bugs"),
report_delayed_bugs: bool = (false, parse_bool, [TRACKED],
"immediately print bugs registered with `delay_span_bug`"),
Expand Down Expand Up @@ -3212,7 +3221,7 @@ mod tests {
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
opts.debugging_opts.treat_err_as_bug = Some(0);
opts.debugging_opts.treat_err_as_bug = Some(1);
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
Expand Down
26 changes: 18 additions & 8 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,19 @@ impl Handler {

fn panic_if_treat_err_as_bug(&self) {
if self.treat_err_as_bug() {
panic!("encountered error with `-Z treat_err_as_bug");
let s = match (self.err_count(), self.flags.treat_err_as_bug.unwrap_or(0)) {
(0, _) => return,
(1, 1) => "aborting due to `-Z treat-err-as-bug=1`".to_string(),
(1, _) => return,
(count, as_bug) => {
format!(
"aborting after {} errors due to `-Z treat-err-as-bug={}`",
count,
as_bug,
)
}
};
panic!(s);
}
}

Expand Down Expand Up @@ -645,14 +657,12 @@ impl Handler {
1 => "aborting due to previous error".to_string(),
_ => format!("aborting due to {} previous errors", self.err_count())
};
let err_as_bug = self.flags.treat_err_as_bug.unwrap_or(0);
if self.err_count() >= err_as_bug {
return;
}

let _ = if self.treat_err_as_bug() {
self.fatal(&s)
} else {
// only emit one backtrace when using `-Z treat-err-as-bug=X`
DiagnosticBuilder::new(self, Fatal, &s).emit();
FatalError
};
let _ = self.fatal(&s);

let can_show_explain = self.emitter.borrow().should_show_explain();
let are_there_diagnostics = !self.emitted_diagnostic_codes.borrow().is_empty();
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn run(mut options: Options) -> isize {
let source_map = Lrc::new(SourceMap::new(sessopts.file_path_mapping()));
let handler =
errors::Handler::with_tty_emitter(ColorConfig::Auto,
true, false,
true, None,
Some(source_map.clone()));

let mut sess = session::build_session_(
Expand Down

0 comments on commit c41ddf1

Please sign in to comment.