Skip to content
Permalink
Browse files

Keep current behavior while accepting error count

  • Loading branch information...
estebank committed Mar 7, 2019
1 parent 754037d commit c41ddf177380e96e873d625cb7ce87468eed85e4
Showing with 30 additions and 11 deletions.
  1. +11 −2 src/librustc/session/config.rs
  2. +18 −8 src/librustc_errors/lib.rs
  3. +1 −1 src/librustdoc/test.rs
@@ -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");
@@ -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;
@@ -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`"),
@@ -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();
@@ -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);
}
}

@@ -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();
@@ -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_(

0 comments on commit c41ddf1

Please sign in to comment.
You can’t perform that action at this time.