Skip to content

Commit 1a54961

Browse files
committed
Allow -Z treat-err-as-bug=0
1 parent 62ebe3a commit 1a54961

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub struct HandlerFlags {
519519
/// If false, warning-level lints are suppressed.
520520
/// (rustc: see `--allow warnings` and `--cap-lints`)
521521
pub can_emit_warnings: bool,
522-
/// If true, error-level diagnostics are upgraded to bug-level.
522+
/// If Some, the Nth error-level diagnostic is upgraded to bug-level.
523523
/// (rustc: see `-Z treat-err-as-bug`)
524524
pub treat_err_as_bug: Option<NonZeroUsize>,
525525
/// If true, immediately emit diagnostics that would otherwise be buffered.
@@ -1719,19 +1719,17 @@ impl HandlerInner {
17191719
match (
17201720
self.err_count() + self.lint_err_count,
17211721
self.delayed_bug_count(),
1722-
self.flags.treat_err_as_bug.map(|c| c.get()).unwrap_or(0),
1722+
self.flags.treat_err_as_bug.map(|c| c.get()).unwrap(),
17231723
) {
17241724
(1, 0, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"),
17251725
(0, 1, 1) => panic!("aborting due delayed bug with `-Z treat-err-as-bug=1`"),
1726-
(count, delayed_count, as_bug) => {
1726+
(count, delayed_count, val) => {
17271727
if delayed_count > 0 {
17281728
panic!(
1729-
"aborting after {count} errors and {delayed_count} delayed bugs due to `-Z treat-err-as-bug={as_bug}`",
1729+
"aborting after {count} errors and {delayed_count} delayed bugs due to `-Z treat-err-as-bug={val}`",
17301730
)
17311731
} else {
1732-
panic!(
1733-
"aborting after {count} errors due to `-Z treat-err-as-bug={as_bug}`",
1734-
)
1732+
panic!("aborting after {count} errors due to `-Z treat-err-as-bug={val}`")
17351733
}
17361734
}
17371735
}

compiler/rustc_session/src/options.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::collections::BTreeMap;
2020

2121
use std::collections::hash_map::DefaultHasher;
2222
use std::hash::Hasher;
23-
use std::num::NonZeroUsize;
23+
use std::num::{IntErrorKind, NonZeroUsize};
2424
use std::path::PathBuf;
2525
use std::str;
2626

@@ -385,7 +385,7 @@ mod desc {
385385
"`all` (default), `except-unused-generics`, `except-unused-functions`, or `off`";
386386
pub const parse_instrument_xray: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), or a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit`";
387387
pub const parse_unpretty: &str = "`string` or `string=string`";
388-
pub const parse_treat_err_as_bug: &str = "either no value or a number bigger than 0";
388+
pub const parse_treat_err_as_bug: &str = "either no value or a positive number";
389389
pub const parse_trait_solver: &str =
390390
"one of the supported solver modes (`classic`, `next`, or `next-coherence`)";
391391
pub const parse_lto: &str =
@@ -971,10 +971,16 @@ mod parse {
971971

972972
pub(crate) fn parse_treat_err_as_bug(slot: &mut Option<NonZeroUsize>, v: Option<&str>) -> bool {
973973
match v {
974-
Some(s) => {
975-
*slot = s.parse().ok();
976-
slot.is_some()
977-
}
974+
Some(s) => match s.parse() {
975+
Ok(val) => {
976+
*slot = Some(val);
977+
true
978+
}
979+
Err(e) => {
980+
*slot = None;
981+
e.kind() == &IntErrorKind::Zero
982+
}
983+
},
978984
None => {
979985
*slot = NonZeroUsize::new(1);
980986
true
@@ -1832,7 +1838,7 @@ written to standard error output)"),
18321838
trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
18331839
"generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
18341840
treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],
1835-
"treat error number `val` that occurs as bug"),
1841+
"treat the nth error that occurs as bug (default: 0 - don't treat errors as bugs)"),
18361842
trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],
18371843
"in diagnostics, use heuristics to shorten paths referring to items"),
18381844
tune_cpu: Option<String> = (None, parse_opt_string, [TRACKED],

0 commit comments

Comments
 (0)