rust/compiler/rustc_errors/src
Nicholas Nethercote 5d9dfbd08f Stop using String for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!

This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.

With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123)  // macro call

struct_span_code_err!(dcx, span, E0123, "msg");  // bare ident arg to macro call

\#[diag(name, code = "E0123")]  // string
struct Diag;
```

With the new code, they all use the `E0123` constant.
```
E0123  // constant

struct_span_code_err!(dcx, span, E0123, "msg");  // constant

\#[diag(name, code = E0123)]  // constant
struct Diag;
```

The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
  used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
  moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
  code constants and the `DIAGNOSTIC_TABLES`. This is in its new
  `codes.rs` file.
2024-01-29 07:41:41 +11:00
..
json Rename many DiagCtxt and EarlyDiagCtxt locals. 2023-12-18 16:06:22 +11:00
markdown apply fmt 2024-01-11 15:04:48 +03:00
annotate_snippet_emitter_writer.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
codes.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
diagnostic_builder.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
diagnostic_impls.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
diagnostic.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
emitter.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
error.rs Make translate_message return result and add tests 2023-01-08 23:35:43 +01:00
json.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
lib.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
lock.rs bump windows crate 0.46 -> 0.48 in workspace 2023-05-09 18:20:13 +03:00
registry.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
snippet.rs Create AnnotationColumn struct to fix hard tab column numbers in errors 2023-03-28 09:18:55 -04:00
styled_buffer.rs Replace some _ == _ || _ == _s with matches!(_, _ | _)s 2023-01-30 12:26:26 +00:00
tests.rs Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
translation.rs Restore behavior when primary bundle is missing 2023-02-23 01:14:10 +01:00