Skip to content

Commit 02af015

Browse files
committed
[error index] Move some logic from build.rs to main.rs
1 parent 37b55c8 commit 02af015

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

src/tools/error_index_generator/build.rs

-32
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ fn main() {
77
// Note that we could skip one of the .. but this ensures we at least loosely find the right
88
// directory.
99
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
10-
let dest = out_dir.join("error_codes.rs");
1110

1211
let error_codes_path = "../../../compiler/rustc_error_codes/src/error_codes.rs";
1312

@@ -29,35 +28,4 @@ fn main() {
2928
let md_content = fs::read_to_string(entry.path()).unwrap();
3029
fs::write(&out_dir.join(entry.file_name()), &md_content).unwrap();
3130
}
32-
33-
let mut all = String::new();
34-
all.push_str(
35-
r###"
36-
fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
37-
let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
38-
macro_rules! register_diagnostics {
39-
($($ecode:ident: $message:expr,)*) => (
40-
register_diagnostics!{$($ecode:$message,)* ;}
41-
);
42-
43-
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
44-
$(
45-
{long_codes.extend([
46-
(stringify!($ecode), Some($message)),
47-
].iter());}
48-
)*
49-
$(
50-
{long_codes.extend([
51-
stringify!($code),
52-
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
53-
)*
54-
)
55-
}
56-
"###,
57-
);
58-
all.push_str(r#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"#);
59-
all.push_str("\nlong_codes\n");
60-
all.push_str("}\n");
61-
62-
fs::write(&dest, all).unwrap();
6331
}

src/tools/error_index_generator/main.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,26 @@ fn main() {
277277
}
278278
}
279279

280-
include!(concat!(env!("OUT_DIR"), "/error_codes.rs"));
280+
fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
281+
let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
282+
macro_rules! register_diagnostics {
283+
($($ecode:ident: $message:expr,)*) => (
284+
register_diagnostics!{$($ecode:$message,)* ;}
285+
);
286+
287+
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
288+
$(
289+
{long_codes.extend([
290+
(stringify!($ecode), Some($message)),
291+
].iter());}
292+
)*
293+
$(
294+
{long_codes.extend([
295+
stringify!($code),
296+
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
297+
)*
298+
)
299+
}
300+
include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));
301+
long_codes
302+
}

0 commit comments

Comments
 (0)