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

Cleanup error handlers some more #118587

Merged
merged 13 commits into from
Dec 6, 2023

Commits on Dec 4, 2023

  1. Give Handler::fatal and Session::fatal the same return type.

    Currently, `Handler::fatal` returns `FatalError`. But `Session::fatal`
    returns `!`, because it calls `Handler::fatal` and then calls `raise` on
    the result. This inconsistency is unfortunate.
    
    This commit changes `Handler::fatal` to do the `raise` itself, changing
    its return type to `!`. This is safe because there are only two calls to
    `Handler::fatal`, one in `rustc_session` and one in
    `rustc_codegen_cranelift`, and they both call `raise` on the result.
    
    `HandlerInner::fatal` still returns `FatalError`, so I renamed it
    `fatal_no_raise` to emphasise the return type difference.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    114380d View commit details
    Browse the repository at this point in the history
  2. Inline and remove DiagnosticBuilder::new_diagnostic_* functions.

    They each have a single call site.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    d4933aa View commit details
    Browse the repository at this point in the history
  3. Inline and remove more DiagnosticBuilder::new_diagnostic_* functions.

    They each have a single call site.
    
    Note: the `make_diagnostic_builder` calls in `lib.rs` will be replaced
    in a subsequent commit.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    ab640ca View commit details
    Browse the repository at this point in the history
  4. Rename some arguments.

    `sess` is a terribly misleading name for a `Handler`! This confused me
    for a bit.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    6a95dee View commit details
    Browse the repository at this point in the history
  5. Always use G for EmissionGuarantee type variables.

    That's what is mostly used. This commit changes a few `EM` and `E` and
    `T` type variables to `G`.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    ed95f39 View commit details
    Browse the repository at this point in the history
  6. Avoid Diagnostic::new_with_code(..., None, ...).

    `Diagnostic::new` can be used instead.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    32dc78e View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    d51b3db View commit details
    Browse the repository at this point in the history
  8. De-genericize some IntoDiagnostic impls.

    These impls are all needed for just a single `IntoDiagnostic` type, not
    a family of them.
    
    Note that `ErrorGuaranteed` is the default type parameter for
    `IntoDiagnostic`.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    b7e18ca View commit details
    Browse the repository at this point in the history
  9. Use DiagnosticBuilder::new more.

    By making it generic, instead of only for `EmissionGuarantee = ()`, we
    can use it everywhere.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    8c20ad6 View commit details
    Browse the repository at this point in the history
  10. Move some HandlerInner functions to Handler.

    `Handler` is a wrapper around `HanderInner`. Some functions on
    on `Handler` just forward to the samed-named functions on
    `HandlerInner`.
    
    This commit removes as many of those as possible, implementing functions
    on `Handler` where possible, to avoid the boilerplate required for
    forwarding. The commit is moderately large but it's very mechanical.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    a8ff867 View commit details
    Browse the repository at this point in the history
  11. Remove HandlerInner::emit.

    This is weird: `HandlerInner::emit` calls
    `HandlerInner::emit_diagnostic`, but only after doing a
    `treat-err-as-bug` check. Which is fine, *except* that there are
    multiple others paths for an `Error` or `Fatal` diagnostic to be passed
    to `HandlerInner::emit_diagnostic` without going through
    `HandlerInner::emit`, e.g. `Handler::span_err` call
    `Handler::emit_diag_at_span`, which calls `emit_diagnostic`.
    So that suggests that the coverage for `treat-err-as-bug` is incomplete.
    
    This commit removes `HandlerInner::emit` and moves the
    `treat-err-as-bug` check to `HandlerInner::emit_diagnostic`, so it
    cannot by bypassed.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    883bdb7 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    3ab05ca View commit details
    Browse the repository at this point in the history
  13. Inline and remove fatal_no_raise.

    This makes `Handler::fatal` more like `Handler::{err,warn,bug,note}`.
    nnethercote committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    7811c97 View commit details
    Browse the repository at this point in the history