@@ -168,20 +168,24 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
168168 } ;
169169
170170 // Output error metadata to `tmp/extended-errors/<target arch>/<crate name>.json`
171- let target_triple = env:: var ( "CFG_COMPILER_HOST_TRIPLE" )
172- . ok ( ) . expect ( "unable to determine target arch from $CFG_COMPILER_HOST_TRIPLE" ) ;
173-
174- with_registered_diagnostics ( |diagnostics| {
175- if let Err ( e) = output_metadata ( ecx,
176- & target_triple,
177- & crate_name. name . as_str ( ) ,
178- & diagnostics) {
179- ecx. span_bug ( span, & format ! (
180- "error writing metadata for triple `{}` and crate `{}`, error: {}, cause: {:?}" ,
181- target_triple, crate_name, e. description( ) , e. cause( )
182- ) ) ;
183- }
184- } ) ;
171+ if let Ok ( target_triple) = env:: var ( "CFG_COMPILER_HOST_TRIPLE" ) {
172+ with_registered_diagnostics ( |diagnostics| {
173+ if let Err ( e) = output_metadata ( ecx,
174+ & target_triple,
175+ & crate_name. name . as_str ( ) ,
176+ & diagnostics) {
177+ ecx. span_bug ( span, & format ! (
178+ "error writing metadata for triple `{}` and crate `{}`, error: {}, \
179+ cause: {:?}",
180+ target_triple, crate_name, e. description( ) , e. cause( )
181+ ) ) ;
182+ }
183+ } ) ;
184+ } else {
185+ ecx. span_err ( span, & format ! (
186+ "failed to write metadata for crate `{}` because $CFG_COMPILER_HOST_TRIPLE is not set" ,
187+ crate_name) ) ;
188+ }
185189
186190 // Construct the output expression.
187191 let ( count, expr) =
0 commit comments