about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2023-12-23Introduce `DiagCtxt::treat_next_err_as_bug`.Nicholas Nethercote-7/+8
To fix a FIXME.
2023-12-23Remove unnecessary line breaks from two string literals.Nicholas Nethercote-4/+2
2023-12-23Tweak `flush_delayed`.Nicholas Nethercote-10/+11
- Take a `Vec` instead of an iterator, because that's all that is needed. - Do an early return for the "no bugs" case. - Use `enumerate` and an `i == 0` test to identify the first bug. Those changes mean the `no_bug` variable can be removed, which I found hard to read.
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-12/+6
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
2023-12-23Fix a couple of left-over references to `Handler`.Nicholas Nethercote-2/+2
2023-12-23Improve `use` items in `compiler/rustc_errors/src/lib.rs`.Nicholas Nethercote-30/+27
There are a bunch of them about 400 lines down, which is weird and annoying. This commit moves them up and puts them in a more sensible order.
2023-12-23Streamline `struct_lint_level`.Nicholas Nethercote-53/+0
We can just get the error level in the `match` and then use `DiagnosticBuilder::new`. This then means a number of `DiagCtxt` functions are no longer needed, because this was the one place that used them. Note: the commit changes the treatment of spans for `Expect`, which was different to all the other cases, but this has no apparent effect.
2023-12-23Add comments to `Level`.Nicholas Nethercote-5/+59
There is room for improvement on some of these, but something is better than nothing.
2023-12-19Remove unused `DiagCtxt::span_bug_no_panic`.Nicholas Nethercote-7/+0
2023-12-19De-weirdify `fatally_break_rust`.Nicholas Nethercote-0/+13
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.
2023-12-19Introduce `DiagCtxt::struct_bug`.Nicholas Nethercote-1/+9
This makes `DiagCtxt::bug` look like the other similar functions.
2023-12-19Add `EmitResult` associated type to `EmissionGuarantee`.Nicholas Nethercote-18/+18
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.
2023-12-19Remove `struct_diagnostic` and `G::make_diagnostic_builder`.Nicholas Nethercote-15/+0
`EmissionGuarantee` no longer determines the error level, the `create_*` functions do.
2023-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-6/+6
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.
2023-12-18Use `.into_diagnostic()` less.Nicholas Nethercote-0/+1
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.
2023-12-18Rename `HandlerFlags` as `DiagCtxtFlags`.Nicholas Nethercote-4/+4
2023-12-18Rename `HandlerInner` as `DiagCtxtInner`.Nicholas Nethercote-9/+9
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-4/+4
2023-12-15Split `Handler::emit_diagnostic` in two.Nicholas Nethercote-16/+35
Currently, `emit_diagnostic` takes `&mut self`. This commit changes it so `emit_diagnostic` takes `self` and the new `emit_diagnostic_without_consuming` function takes `&mut self`. I find the distinction useful. The former case is much more common, and avoids a bunch of `mut` and `&mut` occurrences. We can also restrict the latter with `pub(crate)` which is nice.
2023-12-15Remove `Handler::emit_diag_at_span`.Nicholas Nethercote-23/+9
Compare `Handler::warn` and `Handler::span_warn`. Conceptually they are almost identical. But their implementations are weirdly different. `warn`: - calls `DiagnosticBuilder::<()>::new(self, Warning(None), msg)`, then `emit()` - which calls `G::diagnostic_builder_emit_producing_guarantee(self)` - which calls `handler.emit_diagnostic(&mut db.inner.diagnostic)` `span_warn`: - calls `self.emit_diag_at_span(Diagnostic::new(Warning(None), msg), span)` - which calls `self.emit_diagnostic(diag.set_span(sp))` I.e. they both end up at `emit_diagnostic`, but take very different routes to get there. This commit changes `span_*` and similar ones to not use `emit_diag_at_span`. Instead they just call `struct_span_*` + `emit`. Some nice side-effects of this: - `span_fatal` and `span_fatal_with_code` don't need `FatalError.raise()`, because `emit` does that. - `span_err` and `span_err_with_code` doesn't need `unwrap`. - `struct_span_note`'s `span` arg type is changed from `Span` to `impl Into<MultiSpan>` like all the other functions.
2023-12-15Avoid `DiagnosticBuilder::<T>::new` calls.Nicholas Nethercote-4/+4
The `Handler` functions that directly emit diagnostics can be more easily implemented using `struct_foo(msg).emit()`. This mirrors `Handler::emit_err` which just does `create_err(err).emit()`. `Handler::bug` is not converted because of weirdness involving conflation bugs and fatal errors with `EmissionGuarantee`. I'll fix that later.
2023-12-15Change `msg: impl Into<String>` for bug diagnostics.Nicholas Nethercote-7/+7
To `msg: impl Into<DiagnosticMessage>`, like all the other diagnostics. For consistency.
2023-12-14Avoid `struct_diagnostic` where possible.Nicholas Nethercote-2/+17
It's necessary for `derive(Diagnostic)`, but is best avoided elsewhere because there are clearer alternatives. This required adding `Handler::struct_almost_fatal`.
2023-12-14Inline and remove `HandlerInner::emit_diag_at_span`.Nicholas Nethercote-5/+1
It has a single call site.
2023-12-14Remove unused `Handler::treat_err_as_bug`.Nicholas Nethercote-5/+0
2023-12-04Inline and remove `fatal_no_raise`.Nicholas Nethercote-10/+3
This makes `Handler::fatal` more like `Handler::{err,warn,bug,note}`.
2023-12-04Make `Handler::{err,bug}` more like `Handler::{warn,note}`.Nicholas Nethercote-10/+3
2023-12-04Remove `HandlerInner::emit`.Nicholas Nethercote-12/+12
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.
2023-12-04Move some `HandlerInner` functions to `Handler`.Nicholas Nethercote-212/+164
`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.
2023-12-04Use `DiagnosticBuilder::new` more.Nicholas Nethercote-5/+5
By making it generic, instead of only for `EmissionGuarantee = ()`, we can use it everywhere.
2023-12-04Inline and remove more `DiagnosticBuilder::new_diagnostic_*` functions.Nicholas Nethercote-3/+3
They each have a single call site. Note: the `make_diagnostic_builder` calls in `lib.rs` will be replaced in a subsequent commit.
2023-12-04Give `Handler::fatal` and `Session::fatal` the same return type.Nicholas Nethercote-6/+7
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.
2023-12-02`Handler` tweaks.Nicholas Nethercote-8/+6
- Avoid unnecessary `inner` local variables. - Use `borrow_mut` everywhere (instead of the synonym `lock`).
2023-12-02Rename `Handler::delay_good_path_bug` as `Handler::good_path_delayed_bug`.Nicholas Nethercote-12/+12
In line with the previous commits.
2023-12-02Rename `HandlerInner::delayed_span_bugs` as `HandlerInner::span_delayed_bugs`.Nicholas Nethercote-14/+14
For reasons similar to the previous commit.
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-9/+12
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-12-02Rename `*note_without_error` as `*note`.Nicholas Nethercote-10/+3
Because the variant name in `Level` is `Note`, and the `without_error` suffix is omitted in similar cases like `struct_allow` and `struct_help`.
2023-12-02Rename `HandlerInner::failure` as `HandlerInner::failure_note`.Nicholas Nethercote-4/+4
To match the `FailureNote` variant of `Level`.
2023-12-02Rename `Handler::span_note_diag` as `struct_span_note`.Nicholas Nethercote-1/+1
Because `span_note_diag` doesn't follow the naming structure used for the error reporting functions.
2023-12-02Remove an unnecessary local variable.Nicholas Nethercote-2/+1
2023-12-02Return `ErrorGuaranteed` from `span_err_with_code` methods.Nicholas Nethercote-2/+3
`ErrorGuaranteed` should be used for all error methods involving the `Error` level, e.g. as is done for the corresponding `span_err` methods.
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-2/+1
Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter.
2023-11-24Show number in error message even for one errorNilstrieb-1/+1
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-11-13Auto merge of #116866 - slanterns:inspect-stabilize, r=BurntSushibors-1/+0
Stabilize `result_option_inspect` This PR stabilizes `result_option_inspect`: ```rust // core::option impl Option<T> { pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self; } // core::result impl Result<T, E> { pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self; pub fn inspect_err<F: FnOnce(&E)>(self, f: F) -> Self; } ``` <br> Tracking issue: https://github.com/rust-lang/rust/issues/91345. Implementation PR: https://github.com/rust-lang/rust/pull/91346. Closes https://github.com/rust-lang/rust/issues/91345.
2023-10-30Don't emit delayed good-path bugs on panicMichael Goulet-1/+1
2023-10-26Stash and cancel cycle errors for auto trait leakage in opaquesMichael Goulet-0/+2
2023-10-18Remove `#![feature(result_option_inspect)]` from the compilerSlanterns-1/+0
2023-10-16Rollup merge of #115196 - chenyukang:yukang-fix-86094, r=estebankMatthias Krüger-0/+1
Suggest adding `return` if the for semi which can coerce to the fn return type Fixes #86094 r? `@estebank`
2023-10-15Suggest adding `return` if the type of unused semi return value can coerce ↵yukang-0/+1
to the fn return type