Skip to content

Commit 4de4f30

Browse files
Fix error index generator for new register_diagnostics API
1 parent 3f1dc32 commit 4de4f30

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

src/tools/error_index_generator/build.rs

+22-29
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ fn main() {
1414
if entry.file_name() == "error_codes.rs" {
1515
println!("cargo:rerun-if-changed={}", entry.path().to_str().unwrap());
1616
let file = fs::read_to_string(entry.path()).unwrap()
17-
.replace("use syntax::{register_diagnostics, register_long_diagnostics};", "")
18-
.replace("use syntax::register_diagnostics;", "")
19-
.replace("use syntax::register_long_diagnostics;", "");
17+
.replace("syntax::register_diagnostics!", "register_diagnostics!");
2018
let contents = format!("(|| {{\n{}\n}})();", file);
2119

2220
fs::write(&out_dir.join(&format!("error_{}.rs", idx)), &contents).unwrap();
@@ -26,36 +24,31 @@ fn main() {
2624
}
2725

2826
let mut all = String::new();
29-
all.push_str("fn register_all() -> Vec<(&'static str, Option<&'static str>)> {\n");
30-
all.push_str("let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();\n");
31-
all.push_str(r#"
32-
macro_rules! register_diagnostics {
33-
($($code:tt),*) => {{
34-
long_codes.extend([$(
35-
stringify!($code),
36-
)*].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());
37-
}};
38-
($($code:tt),*,) => {{
39-
long_codes.extend([$(
40-
stringify!($code),
41-
)*].iter().cloned().map(|s| (s, None)));
42-
}}
43-
}
27+
all.push_str(r###"
28+
fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
29+
let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
30+
macro_rules! register_diagnostics {
31+
($($ecode:ident: $message:expr,)*) => (
32+
register_diagnostics!{$($ecode:$message,)* ;}
33+
);
4434
45-
macro_rules! register_long_diagnostics {
46-
($($code:tt: $description:tt),*) => {
47-
{long_codes.extend([$(
48-
(stringify!($code), Some(stringify!($description))),
49-
)*].iter());}
50-
};
51-
($($code:tt: $description:tt),*,) => {
52-
{long_codes.extend([$(
53-
(stringify!($code), Some(stringify!($description))),
54-
)*].iter());}
35+
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
36+
$(
37+
{long_codes.extend([
38+
(stringify!($ecode), Some(stringify!($message))),
39+
].iter());}
40+
)*
41+
$(
42+
{long_codes.extend([
43+
stringify!($code),
44+
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
45+
)*
46+
)
5547
}
56-
}"#);
48+
"###);
5749
for idx in 0..idx {
5850
all.push_str(&format!(r#"include!(concat!(env!("OUT_DIR"), "/error_{}.rs"));"#, idx));
51+
all.push_str("\n");
5952
}
6053
all.push_str("\nlong_codes\n");
6154
all.push_str("}\n");

0 commit comments

Comments
 (0)