Skip to content

Commit 0190394

Browse files
committed
Auto merge of #115690 - ShE3py:Z-treat-err-as-bug, r=petrochenkov
Allow `-Z treat-err-as-bug=0` Makes `-Z treat-err-as-bug=0` behave as if the option wasn't present instead of asking the value to be ⩾ 1. This enables a quick on/off of the option, as you only need to change one character instead of removing the whole `-Z`. Also update some text, e.g. ```bash $ rustc -Z help | grep treat-err-as-bug -Z treat-err-as-bug=val -- treat error number `val` that occurs as bug ``` where the value could be interpreted as an error code instead of an ordinal.
2 parents 03c199a + 3dd0419 commit 0190394

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

compiler/rustc_errors/src/lib.rs

+5-7
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

+14-7
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

@@ -387,7 +387,7 @@ mod desc {
387387
"`all` (default), `except-unused-generics`, `except-unused-functions`, or `off`";
388388
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`";
389389
pub const parse_unpretty: &str = "`string` or `string=string`";
390-
pub const parse_treat_err_as_bug: &str = "either no value or a number bigger than 0";
390+
pub const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
391391
pub const parse_trait_solver: &str =
392392
"one of the supported solver modes (`classic`, `next`, or `next-coherence`)";
393393
pub const parse_lto: &str =
@@ -986,10 +986,16 @@ mod parse {
986986

987987
pub(crate) fn parse_treat_err_as_bug(slot: &mut Option<NonZeroUsize>, v: Option<&str>) -> bool {
988988
match v {
989-
Some(s) => {
990-
*slot = s.parse().ok();
991-
slot.is_some()
992-
}
989+
Some(s) => match s.parse() {
990+
Ok(val) => {
991+
*slot = Some(val);
992+
true
993+
}
994+
Err(e) => {
995+
*slot = None;
996+
e.kind() == &IntErrorKind::Zero
997+
}
998+
},
993999
None => {
9941000
*slot = NonZeroUsize::new(1);
9951001
true
@@ -1846,7 +1852,8 @@ written to standard error output)"),
18461852
trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
18471853
"generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
18481854
treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],
1849-
"treat error number `val` that occurs as bug"),
1855+
"treat the `val`th error that occurs as bug (default if not specified: 0 - don't treat errors as bugs. \
1856+
default if specified without a value: 1 - treat the first error as bug)"),
18501857
trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],
18511858
"in diagnostics, use heuristics to shorten paths referring to items"),
18521859
tune_cpu: Option<String> = (None, parse_opt_string, [TRACKED],

0 commit comments

Comments
 (0)