From 634fced396f180eea18a828bdddec3deded61ab8 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Sat, 20 Jun 2015 16:30:01 +1000 Subject: diagnostics: Resurrect the Compiler Error Index. --- src/libsyntax/diagnostics/plugin.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/libsyntax/diagnostics/plugin.rs') diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 2f7e4a16145..aee066807f4 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -10,6 +10,7 @@ use std::cell::RefCell; use std::collections::BTreeMap; +use std::env; use ast; use ast::{Ident, Name, TokenTree}; @@ -20,6 +21,8 @@ use parse::token; use ptr::P; use util::small_vector::SmallVector; +use diagnostics::metadata::output_metadata; + // Maximum width of any line in an extended error description (inclusive). const MAX_DESCRIPTION_WIDTH: usize = 80; @@ -154,7 +157,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, token_tree: &[TokenTree]) -> Box { assert_eq!(token_tree.len(), 3); - let (_crate_name, name) = match (&token_tree[0], &token_tree[2]) { + let (crate_name, name) = match (&token_tree[0], &token_tree[2]) { ( // Crate name. &ast::TtToken(_, token::Ident(ref crate_name, _)), @@ -164,9 +167,18 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, _ => unreachable!() }; - // FIXME (#25705): we used to ensure error code uniqueness and - // output error description JSON metadata here, but the approach - // employed was too brittle. + // Output error metadata to `tmp/extended-errors//.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, &diagnostics) { + ecx.span_bug(span, &format!( + "error writing metadata for triple `{}` and crate `{}`, error: {}, cause: {:?}", + target_triple, crate_name, e.description(), e.cause() + )); + } + }); // Construct the output expression. let (count, expr) = -- cgit 1.4.1-3-g733a5