From 4de4f303e5cee3e40b8e91a381517a457af7b4cc Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 3 Sep 2019 22:04:01 -0400 Subject: [PATCH] Fix error index generator for new register_diagnostics API --- src/tools/error_index_generator/build.rs | 51 ++++++++++-------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/tools/error_index_generator/build.rs b/src/tools/error_index_generator/build.rs index 2ac7351fce4..832aa3b1c8d 100644 --- a/src/tools/error_index_generator/build.rs +++ b/src/tools/error_index_generator/build.rs @@ -14,9 +14,7 @@ fn main() { if entry.file_name() == "error_codes.rs" { println!("cargo:rerun-if-changed={}", entry.path().to_str().unwrap()); let file = fs::read_to_string(entry.path()).unwrap() - .replace("use syntax::{register_diagnostics, register_long_diagnostics};", "") - .replace("use syntax::register_diagnostics;", "") - .replace("use syntax::register_long_diagnostics;", ""); + .replace("syntax::register_diagnostics!", "register_diagnostics!"); let contents = format!("(|| {{\n{}\n}})();", file); fs::write(&out_dir.join(&format!("error_{}.rs", idx)), &contents).unwrap(); @@ -26,36 +24,31 @@ fn main() { } let mut all = String::new(); - all.push_str("fn register_all() -> Vec<(&'static str, Option<&'static str>)> {\n"); - all.push_str("let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();\n"); - all.push_str(r#" -macro_rules! register_diagnostics { - ($($code:tt),*) => {{ - long_codes.extend([$( - stringify!($code), - )*].iter().cloned().map(|s| (s, None)).collect::>()); - }}; - ($($code:tt),*,) => {{ - long_codes.extend([$( - stringify!($code), - )*].iter().cloned().map(|s| (s, None))); - }} -} + all.push_str(r###" +fn register_all() -> Vec<(&'static str, Option<&'static str>)> { + let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new(); + macro_rules! register_diagnostics { + ($($ecode:ident: $message:expr,)*) => ( + register_diagnostics!{$($ecode:$message,)* ;} + ); -macro_rules! register_long_diagnostics { - ($($code:tt: $description:tt),*) => { - {long_codes.extend([$( - (stringify!($code), Some(stringify!($description))), - )*].iter());} - }; - ($($code:tt: $description:tt),*,) => { - {long_codes.extend([$( - (stringify!($code), Some(stringify!($description))), - )*].iter());} + ($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => ( + $( + {long_codes.extend([ + (stringify!($ecode), Some(stringify!($message))), + ].iter());} + )* + $( + {long_codes.extend([ + stringify!($code), + ].iter().cloned().map(|s| (s, None)).collect::>());} + )* + ) } -}"#); +"###); for idx in 0..idx { all.push_str(&format!(r#"include!(concat!(env!("OUT_DIR"), "/error_{}.rs"));"#, idx)); + all.push_str("\n"); } all.push_str("\nlong_codes\n"); all.push_str("}\n");