Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ErrCode #119972

Merged
merged 3 commits into from
Jan 29, 2024
Merged

Add ErrCode #119972

merged 3 commits into from
Jan 29, 2024

Commits on Jan 28, 2024

  1. Sort attributes in compiler/rustc_errors/src/lib.rs.

    As is already done in `rustc_span` and `rustc_data_structures`.
    nnethercote committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    d91d164 View commit details
    Browse the repository at this point in the history
  2. Remove bogus {code} attributes on TraitImplMismatch.

    This makes no sense, and has no effect. I suspect it's been confused
    with a `code = "{code}"` attribute on a subdiagnostic suggestion, where
    it is valid (but the "code" there is suggested source code, rather than
    an error code.)
    nnethercote committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    0321de2 View commit details
    Browse the repository at this point in the history
  3. 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.
    nnethercote committed Jan 28, 2024
    Configuration menu
    Copy the full SHA
    5d9dfbd View commit details
    Browse the repository at this point in the history