Skip to content

Commit c41ddf1

Browse files
committedMar 7, 2019
Keep current behavior while accepting error count
1 parent 754037d commit c41ddf1

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed
 

‎src/librustc/session/config.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,8 @@ macro_rules! options {
816816
Some("crate=integer");
817817
pub const parse_unpretty: Option<&str> =
818818
Some("`string` or `string=string`");
819+
pub const parse_treat_err_as_bug: Option<&str> =
820+
Some("either no value or a number bigger than 0");
819821
pub const parse_lto: Option<&str> =
820822
Some("either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \
821823
`fat`, or omitted");
@@ -1022,6 +1024,13 @@ macro_rules! options {
10221024
}
10231025
}
10241026

1027+
fn parse_treat_err_as_bug(slot: &mut Option<usize>, v: Option<&str>) -> bool {
1028+
match v {
1029+
Some(s) => { *slot = s.parse().ok().filter(|&x| x != 0); slot.unwrap_or(0) != 0 }
1030+
None => { *slot = Some(1); true }
1031+
}
1032+
}
1033+
10251034
fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
10261035
if v.is_some() {
10271036
let mut bool_arg = None;
@@ -1234,7 +1243,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12341243
"parse only; do not compile, assemble, or link"),
12351244
no_codegen: bool = (false, parse_bool, [TRACKED],
12361245
"run all passes except codegen; no output"),
1237-
treat_err_as_bug: Option<usize> = (None, parse_opt_uint, [TRACKED],
1246+
treat_err_as_bug: Option<usize> = (None, parse_treat_err_as_bug, [TRACKED],
12381247
"treat all errors that occur as bugs"),
12391248
report_delayed_bugs: bool = (false, parse_bool, [TRACKED],
12401249
"immediately print bugs registered with `delay_span_bug`"),
@@ -3212,7 +3221,7 @@ mod tests {
32123221
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
32133222

32143223
opts = reference.clone();
3215-
opts.debugging_opts.treat_err_as_bug = Some(0);
3224+
opts.debugging_opts.treat_err_as_bug = Some(1);
32163225
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
32173226

32183227
opts = reference.clone();

‎src/librustc_errors/lib.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,19 @@ impl Handler {
517517

518518
fn panic_if_treat_err_as_bug(&self) {
519519
if self.treat_err_as_bug() {
520-
panic!("encountered error with `-Z treat_err_as_bug");
520+
let s = match (self.err_count(), self.flags.treat_err_as_bug.unwrap_or(0)) {
521+
(0, _) => return,
522+
(1, 1) => "aborting due to `-Z treat-err-as-bug=1`".to_string(),
523+
(1, _) => return,
524+
(count, as_bug) => {
525+
format!(
526+
"aborting after {} errors due to `-Z treat-err-as-bug={}`",
527+
count,
528+
as_bug,
529+
)
530+
}
531+
};
532+
panic!(s);
521533
}
522534
}
523535

@@ -645,14 +657,12 @@ impl Handler {
645657
1 => "aborting due to previous error".to_string(),
646658
_ => format!("aborting due to {} previous errors", self.err_count())
647659
};
660+
let err_as_bug = self.flags.treat_err_as_bug.unwrap_or(0);
661+
if self.err_count() >= err_as_bug {
662+
return;
663+
}
648664

649-
let _ = if self.treat_err_as_bug() {
650-
self.fatal(&s)
651-
} else {
652-
// only emit one backtrace when using `-Z treat-err-as-bug=X`
653-
DiagnosticBuilder::new(self, Fatal, &s).emit();
654-
FatalError
655-
};
665+
let _ = self.fatal(&s);
656666

657667
let can_show_explain = self.emitter.borrow().should_show_explain();
658668
let are_there_diagnostics = !self.emitted_diagnostic_codes.borrow().is_empty();

‎src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn run(mut options: Options) -> isize {
6767
let source_map = Lrc::new(SourceMap::new(sessopts.file_path_mapping()));
6868
let handler =
6969
errors::Handler::with_tty_emitter(ColorConfig::Auto,
70-
true, false,
70+
true, None,
7171
Some(source_map.clone()));
7272

7373
let mut sess = session::build_session_(

0 commit comments

Comments
 (0)
Please sign in to comment.