summary refs log tree commit diff
path: root/compiler/rustc_errors/src/lib.rs
AgeCommit message (Collapse)AuthorLines
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
2023-10-13Format all the let chains in compilerMichael Goulet-1/+5
2023-10-08rustdoc: remove rust logo from non-Rust cratesMichael Howell-0/+2
2023-10-05Add a note to duplicate diagnosticsAlex Macleod-3/+8
2023-09-22Allow `-Z treat-err-as-bug=0`Lieselotte-7/+5
Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2023-09-08Auto merge of #115418 - Zoxc:freeze-source, r=oli-obkbors-1/+1
Use `Freeze` for `SourceFile` This uses the `Freeze` type in `SourceFile` to let accessing `external_src` and `lines` be lock-free. Behavior of `add_external_src` is changed to set `ExternalSourceKind::AbsentErr` on a hash mismatch which matches the documentation. `ExternalSourceKind::Unneeded` was removed as it's unused. Based on https://github.com/rust-lang/rust/pull/115401.
2023-09-07Use `Freeze` for `SourceFile.external_src`John Kåre Alsaker-1/+1
2023-09-07Implement refinement lint for RPITITMichael Goulet-3/+3
2023-09-04Add OnceHelp lint level (same as OnceNote, except for help)Urgau-3/+5
2023-09-01Add comment so pub items are not removedChristian Legnitto-0/+2
As suggested in https://github.com/rust-lang/rust/pull/115393, add a comment so someone doesn't clean these up.
2023-08-30Make `termcolor` types public in `rustc_errors`Christian Legnitto-1/+1
After https://github.com/rust-lang/rust/pull/114104, `rust-gpu` is unable to create a custom `Emitter` as the bounds have changed to include `WriteColor`. I was able to work around this by adding `termcolor` as a direct dependency, but I believe this should be exposed as part of `rustc_errors` proper. See https://github.com/rust-lang/rust/pull/102992 for why `rust-gpu` needs to create a custom emitter.
2023-08-30Use conditional synchronization for LockJohn Kåre Alsaker-5/+5
2023-08-24Add comment to the push_trailing functionallaboutevemirolive-2/+16
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
2023-08-18fixKyle Lin-1/+1
2023-08-18lint linksKyle Lin-3/+3