Skip to content

Commit 356da40

Browse files
Adapt error index generator to the new format
1 parent ec50a75 commit 356da40

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,6 +3120,7 @@ dependencies = [
31203120
"graphviz",
31213121
"jobserver",
31223122
"log",
3123+
"measureme",
31233124
"num_cpus",
31243125
"parking_lot 0.9.0",
31253126
"polonius-engine",

src/test/ui/explain.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
er [RFC 401][rfc401], if you have a function declaration `foo`:
1+
Per [RFC 401][rfc401], if you have a function declaration `foo`:
22

33
```
44
// For the purposes of this explanation, all of these

src/tools/error_index_generator/build.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,26 @@ fn main() {
88
// directory.
99
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
1010
let dest = out_dir.join("error_codes.rs");
11-
let mut idx = 0;
12-
for entry in WalkDir::new("../../../src") {
13-
let entry = entry.unwrap();
14-
if entry.file_name() == "error_codes.rs" {
15-
println!("cargo:rerun-if-changed={}", entry.path().to_str().unwrap());
16-
let file = fs::read_to_string(entry.path()).unwrap()
17-
.replace("crate::register_diagnostics!", "register_diagnostics!")
18-
.replace(": include_str!(\"./",
19-
": include_str!(\"../../../../../../../../src/librustc_error_codes/");
20-
let contents = format!("(|| {{\n{}\n}})()", file);
2111

22-
fs::write(&out_dir.join(&format!("error_{}.rs", idx)), &contents).unwrap();
12+
let error_codes_path = "../../../src/librustc_error_codes/error_codes.rs";
13+
14+
println!("cargo:rerun-if-changed={}", error_codes_path);
15+
let file = fs::read_to_string(error_codes_path).unwrap()
16+
.replace("crate::register_diagnostics!", "register_diagnostics!")
17+
.replace(": include_str!(\"./error_codes/", ": include_str!(\"./");
18+
let contents = format!("(|| {{\n{}\n}})()", file);
19+
fs::write(&out_dir.join("all_error_codes.rs"), &contents).unwrap();
2320

24-
idx += 1;
21+
// We copy the md files as well to the target directory.
22+
for entry in WalkDir::new("../../../src/librustc_error_codes/error_codes") {
23+
let entry = entry.unwrap();
24+
match entry.path().extension() {
25+
Some(s) if s == "md" => {}
26+
_ => continue,
2527
}
28+
println!("cargo:rerun-if-changed={}", entry.path().to_str().unwrap());
29+
let md_content = fs::read_to_string(entry.path()).unwrap();
30+
fs::write(&out_dir.join(entry.file_name()), &md_content).unwrap();
2631
}
2732

2833
let mut all = String::new();
@@ -48,10 +53,7 @@ fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
4853
)
4954
}
5055
"###);
51-
for idx in 0..idx {
52-
all.push_str(&format!(r#"include!(concat!(env!("OUT_DIR"), "/error_{}.rs"));"#, idx));
53-
all.push_str("\n");
54-
}
56+
all.push_str(r#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"#);
5557
all.push_str("\nlong_codes\n");
5658
all.push_str("}\n");
5759

0 commit comments

Comments
 (0)