Skip to content

Avoid ICE if environment variable is not set #31248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/libsyntax/diagnostics/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,24 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
};

// Output error metadata to `tmp/extended-errors/<target arch>/<crate name>.json`
let target_triple = env::var("CFG_COMPILER_HOST_TRIPLE")
.ok().expect("unable to determine target arch from $CFG_COMPILER_HOST_TRIPLE");

with_registered_diagnostics(|diagnostics| {
if let Err(e) = output_metadata(ecx,
&target_triple,
&crate_name.name.as_str(),
&diagnostics) {
ecx.span_bug(span, &format!(
"error writing metadata for triple `{}` and crate `{}`, error: {}, cause: {:?}",
target_triple, crate_name, e.description(), e.cause()
));
}
});
if let Ok(target_triple) = env::var("CFG_COMPILER_HOST_TRIPLE") {
with_registered_diagnostics(|diagnostics| {
if let Err(e) = output_metadata(ecx,
&target_triple,
&crate_name.name.as_str(),
&diagnostics) {
ecx.span_bug(span, &format!(
"error writing metadata for triple `{}` and crate `{}`, error: {}, \
cause: {:?}",
target_triple, crate_name, e.description(), e.cause()
));
}
});
} else {
ecx.span_err(span, &format!(
"failed to write metadata for crate `{}` because $CFG_COMPILER_HOST_TRIPLE is not set",
crate_name));
}

// Construct the output expression.
let (count, expr) =
Expand Down