diff options
| author | Ruud van Asseldonk <ruuda@google.com> | 2016-01-27 22:38:01 +0100 |
|---|---|---|
| committer | Ruud van Asseldonk <ruuda@google.com> | 2016-01-28 22:15:42 +0100 |
| commit | a7f1d12ae4e0adbabc4c371d9959e4adeb4d75dd (patch) | |
| tree | b03427413df90abc1ceaf04bba6adb9075aa85b6 /src/libsyntax/diagnostics | |
| parent | b8b18aac12214d7135a083e2e6946aa197185d49 (diff) | |
| download | rust-a7f1d12ae4e0adbabc4c371d9959e4adeb4d75dd.tar.gz rust-a7f1d12ae4e0adbabc4c371d9959e4adeb4d75dd.zip | |
Avoid ICE if environment variable is not set
Rustdoc could trigger a code path that relied on the $CFG_COMPILER_HOST_TRIPLE environment variable being set, causing an ICE if it was not. This fixes that, emitting an error instead of crashing.
Diffstat (limited to 'src/libsyntax/diagnostics')
| -rw-r--r-- | src/libsyntax/diagnostics/plugin.rs | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index d17ca3892dc..6e389e83591 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -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) = |
