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
This commit is contained in:
parent
1b40f033d2
commit
60f15f096e
|
|
@ -7,12 +7,13 @@ are making a new code, you should write an extended write-up.
|
||||||
|
|
||||||
### Allocating a fresh code
|
### Allocating a fresh code
|
||||||
|
|
||||||
If you want to create a new error, you first need to find the next available
|
Error codes are stored in `compiler/rustc_error_codes`.
|
||||||
code. This is a bit tricky since the codes are defined in various crates. To do
|
|
||||||
it, run this obscure command:
|
To create a new error, you first need to find the next available
|
||||||
|
code. You can find it with `tidy`:
|
||||||
|
|
||||||
```
|
```
|
||||||
./x.py test --stage 0 tidy
|
./x.py test tidy
|
||||||
```
|
```
|
||||||
|
|
||||||
This will invoke the tidy script, which generally checks that your code obeys
|
This will invoke the tidy script, which generally checks that your code obeys
|
||||||
|
|
@ -31,17 +32,16 @@ tidy check (x86_64-apple-darwin)
|
||||||
Here we see the highest error code in use is `E0591`, so we _probably_ want
|
Here we see the highest error code in use is `E0591`, so we _probably_ want
|
||||||
`E0592`. To be sure, run `rg E0592` and check, you should see no references.
|
`E0592`. To be sure, run `rg E0592` and check, you should see no references.
|
||||||
|
|
||||||
Next, open `src/{crate}/diagnostics.rs` within the crate where you wish to issue
|
Ideally, you will write an extended description for your error,
|
||||||
the error (e.g., `compiler/rustc_typeck/src/diagnostics.rs`). Ideally, you will add
|
which will go in `rustc_error_codes/src/error_codes/E0592.md`.
|
||||||
the code (in its proper numerical order) into the `register_long_diagnostics!`
|
To register the error, open `rustc_error_codes/src/error_codes.rs` and add the
|
||||||
macro, sort of like this:
|
code (in its proper numerical order) into` register_diagnostics!` macro, like
|
||||||
|
this:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
register_long_diagnostics! {
|
register_diagnostics! {
|
||||||
...
|
...
|
||||||
E0592: r##"
|
E0592: include_str!("./error_codes/E0592.md"),
|
||||||
Your extended error text goes here!
|
|
||||||
"##,
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -73,3 +73,7 @@ struct_span_err!(...)
|
||||||
.span_note(another_span, "some separate note, probably avoid these")
|
.span_note(another_span, "some separate note, probably avoid these")
|
||||||
.emit_()
|
.emit_()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For an example of a PR adding an error code, see [#76143].
|
||||||
|
|
||||||
|
[#76143]: https://github.com/rust-lang/rust/pull/76143
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue