Commit 82cf3a4
committed
Auto merge of rust-lang#66314 - GuillaumeGomez:move-error-codes, r=Centril
Move error codes
Works towards rust-lang#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>File tree
556 files changed
+13256
-13967
lines changed- src
- librustc_codegen_ssa
- mir
- librustc_driver
- librustc_error_codes
- error_codes
- librustc_interface
- librustc_lint
- librustc_metadata
- librustc_mir
- borrow_check/nll/type_check
- hair/pattern
- transform
- check_consts
- util
- librustc_parse
- parser
- librustc_passes
- librustc_plugin
- librustc_privacy
- librustc_resolve
- late
- librustc_typeck
- check
- method
- coherence
- outlives
- variance
- librustc
- hir
- lowering
- infer
- error_reporting
- nice_region_error
- opaque_types
- lint
- middle
- mir/interpret
- traits
- query
- specialize
- ty/query
- libsyntax_ext
- deriving
- libsyntax
- attr
- diagnostics
- feature_gate
- test/ui
- asm
- bad
- error-codes
- issues
- lint
- macros
- simd-intrinsic
- tools/error_index_generator
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| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3120 | 3120 | | |
3121 | 3121 | | |
3122 | 3122 | | |
| 3123 | + | |
3123 | 3124 | | |
3124 | 3125 | | |
3125 | 3126 | | |
3126 | 3127 | | |
3127 | 3128 | | |
3128 | 3129 | | |
3129 | 3130 | | |
| 3131 | + | |
3130 | 3132 | | |
3131 | 3133 | | |
3132 | 3134 | | |
| |||
3439 | 3441 | | |
3440 | 3442 | | |
3441 | 3443 | | |
| 3444 | + | |
3442 | 3445 | | |
3443 | 3446 | | |
3444 | 3447 | | |
| |||
3516 | 3519 | | |
3517 | 3520 | | |
3518 | 3521 | | |
| 3522 | + | |
| 3523 | + | |
| 3524 | + | |
| 3525 | + | |
3519 | 3526 | | |
3520 | 3527 | | |
3521 | 3528 | | |
| |||
3569 | 3576 | | |
3570 | 3577 | | |
3571 | 3578 | | |
| 3579 | + | |
3572 | 3580 | | |
3573 | 3581 | | |
3574 | 3582 | | |
| |||
3605 | 3613 | | |
3606 | 3614 | | |
3607 | 3615 | | |
| 3616 | + | |
3608 | 3617 | | |
3609 | 3618 | | |
3610 | 3619 | | |
| |||
3650 | 3659 | | |
3651 | 3660 | | |
3652 | 3661 | | |
| 3662 | + | |
3653 | 3663 | | |
3654 | 3664 | | |
3655 | 3665 | | |
| |||
3675 | 3685 | | |
3676 | 3686 | | |
3677 | 3687 | | |
| 3688 | + | |
3678 | 3689 | | |
3679 | 3690 | | |
3680 | 3691 | | |
| |||
3703 | 3714 | | |
3704 | 3715 | | |
3705 | 3716 | | |
| 3717 | + | |
3706 | 3718 | | |
3707 | 3719 | | |
3708 | 3720 | | |
| |||
3718 | 3730 | | |
3719 | 3731 | | |
3720 | 3732 | | |
| 3733 | + | |
3721 | 3734 | | |
3722 | 3735 | | |
3723 | 3736 | | |
| |||
3738 | 3751 | | |
3739 | 3752 | | |
3740 | 3753 | | |
| 3754 | + | |
3741 | 3755 | | |
3742 | 3756 | | |
3743 | 3757 | | |
| |||
3751 | 3765 | | |
3752 | 3766 | | |
3753 | 3767 | | |
| 3768 | + | |
3754 | 3769 | | |
3755 | 3770 | | |
3756 | 3771 | | |
| |||
3765 | 3780 | | |
3766 | 3781 | | |
3767 | 3782 | | |
| 3783 | + | |
3768 | 3784 | | |
3769 | 3785 | | |
3770 | 3786 | | |
| |||
3844 | 3860 | | |
3845 | 3861 | | |
3846 | 3862 | | |
| 3863 | + | |
3847 | 3864 | | |
3848 | 3865 | | |
3849 | 3866 | | |
| |||
4380 | 4397 | | |
4381 | 4398 | | |
4382 | 4399 | | |
| 4400 | + | |
4383 | 4401 | | |
4384 | 4402 | | |
4385 | 4403 | | |
| |||
4411 | 4429 | | |
4412 | 4430 | | |
4413 | 4431 | | |
| 4432 | + | |
4414 | 4433 | | |
4415 | 4434 | | |
4416 | 4435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
0 commit comments