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

Fix EmissionGuarantee #119097

Merged
merged 10 commits into from
Dec 22, 2023
Merged

Fix EmissionGuarantee #119097

merged 10 commits into from
Dec 22, 2023

Commits on Dec 18, 2023

  1. Use .into_diagnostic() less.

    This commit replaces this pattern:
    ```
    err.into_diagnostic(dcx)
    ```
    with this pattern:
    ```
    dcx.create_err(err)
    ```
    in a lot of places.
    
    It's a little shorter, makes the error level explicit, avoids some
    `IntoDiagnostic` imports, and is a necessary prerequisite for the next
    commit which will add a `level` arg to `into_diagnostic`.
    
    This requires adding `track_caller` on `create_err` to avoid mucking up
    the output of `tests/ui/track-diagnostics/track4.rs`. It probably should
    have been there already.
    nnethercote committed Dec 18, 2023
    Configuration menu
    Copy the full SHA
    cea683c View commit details
    Browse the repository at this point in the history
  2. Remove unnecessary use items in derived IntoDiagnostic impls.

    Presumably these are a hangover from an earlier time when they were
    necessary.
    nnethercote committed Dec 18, 2023
    Configuration menu
    Copy the full SHA
    18251c4 View commit details
    Browse the repository at this point in the history
  3. Streamline Diagnostic proc macro.

    First, it is parameterized by the name of the diagnostic and the
    DiagCtxt. These are given to `session_diagnostic_derive` and
    `lint_diagnostic_derive`. But the names are hard-wired as "diag" and
    "handler" (should be "dcx"), and there's no clear reason for the
    parameterization. So this commit removes the parameterization and
    hard-wires the names internally.
    
    Once that is done `DiagnosticDeriveBuilder` is reduced to a trivial
    wrapper around `DiagnosticDeriveKind`, and can be removed.
    
    Also, `DiagnosticDerive` and `LintDiagnosticDerive` don't need the
    `builder` field, because it has been reduced to a kind, and they know
    their own kind. This avoids the need for some
    `let`/`else`/`unreachable!` kind checks
    
    And `DiagnosticDeriveVariantBuilder` no longer needs a lifetime, because
    the `parent` field is changed to `kind`, which is now a trivial copy
    type.
    nnethercote committed Dec 18, 2023
    Configuration menu
    Copy the full SHA
    31df50c View commit details
    Browse the repository at this point in the history
  4. Add level arg to into_diagnostic.

    And make all hand-written `IntoDiagnostic` impls generic, by using
    `DiagnosticBuilder::new(dcx, level, ...)` instead of e.g.
    `dcx.struct_err(...)`.
    
    This means the `create_*` functions are the source of the error level.
    This change will let us remove `struct_diagnostic`.
    
    Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`,
    it's necessary to pass diagnostics tests now that it's used in
    `into_diagnostic` functions.
    nnethercote committed Dec 18, 2023
    Configuration menu
    Copy the full SHA
    e7724a2 View commit details
    Browse the repository at this point in the history
  5. Remove struct_diagnostic and G::make_diagnostic_builder.

    `EmissionGuarantee` no longer determines the error level, the `create_*`
    functions do.
    nnethercote committed Dec 18, 2023
    Configuration menu
    Copy the full SHA
    3a5f28f View commit details
    Browse the repository at this point in the history
  6. Add EmitResult associated type to EmissionGuarantee.

    This lets different error levels share the same return type from
    `emit_*`.
    
    - A lot of inconsistencies in the `DiagCtxt` API are removed.
    - `Noted` is removed.
    - `FatalAbort` is introduced for fatal errors (abort via `raise`),
      replacing the `EmissionGuarantee` impl for `!`.
    - `Bug` is renamed `BugAbort` (to avoid clashing with `Level::Bug` and
      to mirror `FatalAbort`), and modified to work in the new way with bug
      errors (abort via panic).
    - Various diagnostic creators and emitters updated to the new, better
      signatures. Note that `DiagCtxt::bug` no longer needs to call
      `panic_any`, because `emit` handles that.
    
    Also shorten the obnoxiously long
    `diagnostic_builder_emit_producing_guarantee` name.
    nnethercote committed Dec 18, 2023
    Configuration menu
    Copy the full SHA
    f545920 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    9ed8733 View commit details
    Browse the repository at this point in the history
  8. Introduce DiagCtxt::struct_bug.

    This makes `DiagCtxt::bug` look like the other similar functions.
    nnethercote committed Dec 18, 2023
    Configuration menu
    Copy the full SHA
    072c157 View commit details
    Browse the repository at this point in the history

Commits on Dec 19, 2023

  1. De-weirdify fatally_break_rust.

    The easter egg ICE on `break rust` is weird: it's the one ICE in the
    entire compiler that doesn't immediately abort, which makes it
    annoyingly inconsistent.
    
    This commit changes it to abort. As part of this, the extra notes are
    now appended onto the bug dignostic, rather than being printed as
    individual note diagnostics, which changes the output format a bit.
    These changes don't interferes with the joke, but they do help with my
    ongoing cleanups to error handling.
    nnethercote committed Dec 19, 2023
    Configuration menu
    Copy the full SHA
    2863298 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    006446e View commit details
    Browse the repository at this point in the history