Skip to content

Commit 5383592

Browse files
committed
Add -Zerror-metrics=PATH to save diagnostic metadata to disk
1 parent 2b78d92 commit 5383592

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Session.vim
1919
*.iml
2020
.vscode
2121
.project
22+
.vim/
2223
.favorites.json
2324
.settings/
2425
.vs/

Diff for: compiler/rustc_driver_impl/src/lib.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ use rustc_metadata::creader::MetadataLoader;
5151
use rustc_metadata::locator;
5252
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
5353
use rustc_session::config::{
54-
nightly_options, ErrorOutputType, Input, OutFileName, OutputType, CG_OPTIONS, Z_OPTIONS,
54+
nightly_options, ErrorOutputType, Input, OutFileName, OutputType, UnstableOptions, CG_OPTIONS,
55+
Z_OPTIONS,
5556
};
5657
use rustc_session::getopts::{self, Matches};
5758
use rustc_session::lint::{Lint, LintId};
@@ -301,6 +302,8 @@ fn run_compiler(
301302
let Some(matches) = handle_options(&default_early_dcx, &args) else { return Ok(()) };
302303

303304
let sopts = config::build_session_options(&mut default_early_dcx, &matches);
305+
// fully initialize ice path static once unstable options are available as context
306+
let _ = ice_path_with_config(Some(&sopts.unstable_opts));
304307

305308
if let Some(ref code) = matches.opt_str("explain") {
306309
handle_explain(&default_early_dcx, diagnostics_registry(), code, sopts.color);
@@ -1307,15 +1310,14 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
13071310
static ICE_PATH: OnceLock<Option<PathBuf>> = OnceLock::new();
13081311

13091312
fn ice_path() -> &'static Option<PathBuf> {
1313+
ice_path_with_config(None)
1314+
}
1315+
1316+
fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<PathBuf> {
13101317
ICE_PATH.get_or_init(|| {
13111318
if !rustc_feature::UnstableFeatures::from_environment(None).is_nightly_build() {
13121319
return None;
13131320
}
1314-
if let Some(s) = std::env::var_os("RUST_BACKTRACE")
1315-
&& s == "0"
1316-
{
1317-
return None;
1318-
}
13191321
let mut path = match std::env::var_os("RUSTC_ICE") {
13201322
Some(s) => {
13211323
if s == "0" {
@@ -1324,7 +1326,10 @@ fn ice_path() -> &'static Option<PathBuf> {
13241326
}
13251327
PathBuf::from(s)
13261328
}
1327-
None => std::env::current_dir().unwrap_or_default(),
1329+
None => config
1330+
.and_then(|unstable_opts| unstable_opts.error_metrics.to_owned())
1331+
.or_else(|| std::env::current_dir().ok())
1332+
.unwrap_or_default(),
13281333
};
13291334
let now: OffsetDateTime = SystemTime::now().into();
13301335
let file_now = now

Diff for: compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,8 @@ options! {
17141714
"emit the bc module with thin LTO info (default: yes)"),
17151715
enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],
17161716
"enforce the type length limit when monomorphizing instances in codegen"),
1717+
error_metrics: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1718+
"stores metrics about the errors being emitted by rustc to disk"),
17171719
export_executable_symbols: bool = (false, parse_bool, [TRACKED],
17181720
"export symbols from executables, as if they were dynamic libraries"),
17191721
external_clangrt: bool = (false, parse_bool, [UNTRACKED],

0 commit comments

Comments
 (0)