@@ -7,12 +7,13 @@ are making a new code, you should write an extended write-up.
7
7
8
8
### Allocating a fresh code
9
9
10
- If you want to create a new error, you first need to find the next available
11
- code. This is a bit tricky since the codes are defined in various crates. To do
12
- it, run this obscure command:
10
+ Error codes are stored in ` compiler/rustc_error_codes ` .
11
+
12
+ To create a new error, you first need to find the next available
13
+ code. You can find it with ` tidy ` :
13
14
14
15
```
15
- ./x.py test --stage 0 tidy
16
+ ./x.py test tidy
16
17
```
17
18
18
19
This will invoke the tidy script, which generally checks that your code obeys
@@ -31,17 +32,16 @@ tidy check (x86_64-apple-darwin)
31
32
Here we see the highest error code in use is ` E0591 ` , so we _ probably_ want
32
33
` E0592 ` . To be sure, run ` rg E0592 ` and check, you should see no references.
33
34
34
- Next, open ` src/{crate}/diagnostics.rs ` within the crate where you wish to issue
35
- the error (e.g., ` compiler/rustc_typeck/src/diagnostics.rs ` ). Ideally, you will add
36
- the code (in its proper numerical order) into the ` register_long_diagnostics! `
37
- macro, sort of like this:
35
+ Ideally, you will write an extended description for your error,
36
+ which will go in ` rustc_error_codes/src/error_codes/E0592.md ` .
37
+ To register the error, open ` rustc_error_codes/src/error_codes.rs ` and add the
38
+ code (in its proper numerical order) into` register_diagnostics! ` macro, like
39
+ this:
38
40
39
41
``` rust
40
- register_long_diagnostics ! {
42
+ register_diagnostics ! {
41
43
...
42
- E0592 : r ## "
43
- Your extended error text goes here!
44
- " ## ,
44
+ E0592 : include_str! (" ./error_codes/E0592.md" ),
45
45
}
46
46
```
47
47
@@ -73,3 +73,7 @@ struct_span_err!(...)
73
73
. span_note (another_span , " some separate note, probably avoid these" )
74
74
. emit_ ()
75
75
```
76
+
77
+ For an example of a PR adding an error code, see [ #76143 ] .
78
+
79
+ [ #76143 ] : https://github.com/rust-lang/rust/pull/76143
0 commit comments