Skip to content

Commit 82cf3a4

Browse files
committed
Auto merge of #66314 - GuillaumeGomez:move-error-codes, r=Centril
Move error codes Works towards #66210. r? @Centril Oh btw, for the ones interested, I used this python script to get all error codes content sorted into one final file: <details> ```python from os import listdir from os.path import isdir, isfile, join def get_error_codes(error_codes, f_path): with open(f_path) as f: short_mode = False lines = f.read().split("\n") i = 0 while i < len(lines): line = lines[i] if not short_mode and line.startswith("E0") and line.endswith(": r##\""): error = line error += "\n" i += 1 while i < len(lines): line = lines[i] error += line if line.endswith("\"##,"): break error += "\n" i += 1 error_codes["long"].append(error) elif line == ';': short_mode = True elif short_mode is True and len(line) > 0 and line != "}": error_codes["short"].append(line) while i + 1 < len(lines): line = lines[i + 1].strip() if not line.startswith("//"): break parts = line.split("//") if len(parts) < 2: break if parts[1].strip().startswith("E0"): break error_codes["short"][-1] += "\n" error_codes["short"][-1] += lines[i + 1] i += 1 i += 1 def loop_dirs(error_codes, cur_dir): for entry in listdir(cur_dir): f = join(cur_dir, entry) if isfile(f) and entry == "error_codes.rs": get_error_codes(error_codes, f) elif isdir(f) and not entry.startswith("librustc_error_codes"): loop_dirs(error_codes, f) def get_error_code(err): x = err.split(",") if len(x) < 2: return err x = x[0] if x.strip().startswith("//"): x = x.split("//")[1].strip() return x.strip() def write_into_file(error_codes, f_path): with open(f_path, "w") as f: f.write("// Error messages for EXXXX errors. Each message should start and end with a\n") f.write("// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and\n") f.write("// use `gq` to wrap paragraphs. Use `:set tw=0` to disable.\n\n") f.write("syntax::register_diagnostics! {\n\n") error_codes["long"].sort() for i in error_codes["long"]: f.write(i) f.write("\n\n") f.write(";\n") error_codes["short"] = sorted(error_codes["short"], key=lambda err: get_error_code(err)) for i in error_codes["short"]: f.write(i) f.write("\n") f.write("}\n") error_codes = { "long": [], "short": [] } loop_dirs(error_codes, "src") write_into_file(error_codes, "src/librustc_error_codes/src/error_codes.rs") ``` </details> And to move the error codes into their own files: <details> ```python import os try: os.mkdir("src/librustc_error_codes/error_codes") except OSError: print("Seems like folder already exist, moving on!") data = '' with open("src/librustc_error_codes/error_codes.rs") as f: x = f.read().split('\n') i = 0 short_part = False while i < len(x): line = x[i] if short_part is False and line.startswith('E0') and line.endswith(': r##"'): err_code = line.split(':')[0] i += 1 content = '' while i < len(x): if x[i] == '"##,': break content += x[i] content += '\n' i += 1 f_path = "src/librustc_error_codes/error_codes/{}.md".format(err_code) with open(f_path, "w") as ff: ff.write(content) data += '{}: include_str!("./error_codes/{}.md"),'.format(err_code, err_code) elif short_part is False and line == ';': short_part is True data += ';\n' else: data += line data += '\n' i += 1 with open("src/librustc_error_codes/error_codes.rs", "w") as f: f.write(data) ``` </details>
2 parents d63b24f + b5b2a89 commit 82cf3a4

File tree

556 files changed

+13256
-13967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

556 files changed

+13256
-13967
lines changed

Cargo.lock

+19
Original file line numberDiff line numberDiff line change
@@ -3120,13 +3120,15 @@ dependencies = [
31203120
"graphviz",
31213121
"jobserver",
31223122
"log",
3123+
"measureme",
31233124
"num_cpus",
31243125
"parking_lot 0.9.0",
31253126
"polonius-engine",
31263127
"rustc-rayon 0.3.0",
31273128
"rustc-rayon-core 0.3.0",
31283129
"rustc_apfloat",
31293130
"rustc_data_structures",
3131+
"rustc_error_codes",
31303132
"rustc_errors",
31313133
"rustc_fs_util",
31323134
"rustc_index",
@@ -3439,6 +3441,7 @@ dependencies = [
34393441
"rustc_apfloat",
34403442
"rustc_codegen_utils",
34413443
"rustc_data_structures",
3444+
"rustc_error_codes",
34423445
"rustc_errors",
34433446
"rustc_fs_util",
34443447
"rustc_incremental",
@@ -3516,6 +3519,10 @@ dependencies = [
35163519
"syntax_pos",
35173520
]
35183521

3522+
[[package]]
3523+
name = "rustc_error_codes"
3524+
version = "0.0.0"
3525+
35193526
[[package]]
35203527
name = "rustc_errors"
35213528
version = "0.0.0"
@@ -3569,6 +3576,7 @@ dependencies = [
35693576
"rustc_codegen_ssa",
35703577
"rustc_codegen_utils",
35713578
"rustc_data_structures",
3579+
"rustc_error_codes",
35723580
"rustc_errors",
35733581
"rustc_incremental",
35743582
"rustc_lint",
@@ -3605,6 +3613,7 @@ dependencies = [
36053613
"log",
36063614
"rustc",
36073615
"rustc_data_structures",
3616+
"rustc_error_codes",
36083617
"rustc_index",
36093618
"rustc_target",
36103619
"syntax",
@@ -3650,6 +3659,7 @@ dependencies = [
36503659
"memmap",
36513660
"rustc",
36523661
"rustc_data_structures",
3662+
"rustc_error_codes",
36533663
"rustc_errors",
36543664
"rustc_index",
36553665
"rustc_parse",
@@ -3675,6 +3685,7 @@ dependencies = [
36753685
"rustc",
36763686
"rustc_apfloat",
36773687
"rustc_data_structures",
3688+
"rustc_error_codes",
36783689
"rustc_errors",
36793690
"rustc_index",
36803691
"rustc_lexer",
@@ -3703,6 +3714,7 @@ dependencies = [
37033714
"bitflags",
37043715
"log",
37053716
"rustc_data_structures",
3717+
"rustc_error_codes",
37063718
"rustc_errors",
37073719
"rustc_lexer",
37083720
"rustc_target",
@@ -3718,6 +3730,7 @@ dependencies = [
37183730
"log",
37193731
"rustc",
37203732
"rustc_data_structures",
3733+
"rustc_error_codes",
37213734
"rustc_errors",
37223735
"rustc_index",
37233736
"rustc_parse",
@@ -3738,6 +3751,7 @@ name = "rustc_plugin_impl"
37383751
version = "0.0.0"
37393752
dependencies = [
37403753
"rustc",
3754+
"rustc_error_codes",
37413755
"rustc_metadata",
37423756
"syntax",
37433757
"syntax_expand",
@@ -3751,6 +3765,7 @@ dependencies = [
37513765
"log",
37523766
"rustc",
37533767
"rustc_data_structures",
3768+
"rustc_error_codes",
37543769
"rustc_typeck",
37553770
"syntax",
37563771
"syntax_pos",
@@ -3765,6 +3780,7 @@ dependencies = [
37653780
"log",
37663781
"rustc",
37673782
"rustc_data_structures",
3783+
"rustc_error_codes",
37683784
"rustc_errors",
37693785
"rustc_metadata",
37703786
"smallvec 1.0.0",
@@ -3844,6 +3860,7 @@ dependencies = [
38443860
"log",
38453861
"rustc",
38463862
"rustc_data_structures",
3863+
"rustc_error_codes",
38473864
"rustc_errors",
38483865
"rustc_index",
38493866
"rustc_target",
@@ -4380,6 +4397,7 @@ dependencies = [
43804397
"lazy_static 1.3.0",
43814398
"log",
43824399
"rustc_data_structures",
4400+
"rustc_error_codes",
43834401
"rustc_errors",
43844402
"rustc_index",
43854403
"rustc_lexer",
@@ -4411,6 +4429,7 @@ dependencies = [
44114429
"fmt_macros",
44124430
"log",
44134431
"rustc_data_structures",
4432+
"rustc_error_codes",
44144433
"rustc_errors",
44154434
"rustc_parse",
44164435
"rustc_target",

src/librustc/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ byteorder = { version = "1.3" }
4040
chalk-engine = { version = "0.9.0", default-features=false }
4141
rustc_fs_util = { path = "../librustc_fs_util" }
4242
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
43+
measureme = "0.4"
44+
rustc_error_codes = { path = "../librustc_error_codes" }

0 commit comments

Comments
 (0)