Skip to content

Commit 677a95f

Browse files
jyn514tshepang
authored andcommitted
Update error codes to match the current implementation
- All codes are in one crate, `rustc_error_codes` - Extended descriptions are loaded using `include_str!` - Give an example of a PR adding an error code
1 parent fb88941 commit 677a95f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/diagnostics/diagnostic-codes.md

+16-12
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ are making a new code, you should write an extended write-up.
77

88
### Allocating a fresh code
99

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`:
1314

1415
```
15-
./x.py test --stage 0 tidy
16+
./x.py test tidy
1617
```
1718

1819
This will invoke the tidy script, which generally checks that your code obeys
@@ -31,17 +32,16 @@ tidy check (x86_64-apple-darwin)
3132
Here we see the highest error code in use is `E0591`, so we _probably_ want
3233
`E0592`. To be sure, run `rg E0592` and check, you should see no references.
3334

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:
3840

3941
```rust
40-
register_long_diagnostics! {
42+
register_diagnostics! {
4143
...
42-
E0592: r##"
43-
Your extended error text goes here!
44-
"##,
44+
E0592: include_str!("./error_codes/E0592.md"),
4545
}
4646
```
4747

@@ -73,3 +73,7 @@ struct_span_err!(...)
7373
.span_note(another_span, "some separate note, probably avoid these")
7474
.emit_()
7575
```
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

Comments
 (0)