]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/diagnostics/plugin.rs
diagnostics: Resurrect the Compiler Error Index.
[rust.git] / src / libsyntax / diagnostics / plugin.rs
index 2f7e4a161450ada19bf8ecb6d902ce1c8b6f391a..aee066807f49a5fef9f6b21071428bf599f2c990 100644 (file)
@@ -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 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<MacResult+'cx> {
     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/<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, &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) =