about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
AgeCommit message (Collapse)AuthorLines
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-40/+40
2023-12-15Rollup merge of #118993 - jyn514:cfg-color, r=WaffleLapkin,NilstriebJubilee-4/+1
use `if cfg!` instead of `#[cfg]` this pr is specifically for waffle because i love it <3 fixes https://github.com/rust-lang/rust/pull/118756#discussion_r1421767649 r? `@WaffleLapkin`
2023-12-16Simplify lint decorator derive tooMichael Goulet-4/+1
2023-12-15use `if cfg` instead of `#[cfg]`jyn-4/+1
this pr is specifically for waffle because i love it <3
2023-12-15Rollup merge of #118888 - compiler-errors:uplift-more-things, r=jackh726Matthias Krüger-0/+6
Uplift `TypeAndMut` and `ClosureKind` to `rustc_type_ir` Uplifts `TypeAndMut` and `ClosureKind` I know I said I was just going to get rid of `TypeAndMut` (https://github.com/rust-lang/types-team/issues/124) but I think this is much simpler, lol r? `@jackh726` or `@lcnr`
2023-12-15Split `Handler::emit_diagnostic` in two.Nicholas Nethercote-26/+47
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-12Uplift ClosureKindMichael Goulet-0/+6
2023-12-12Rollup merge of #118756 - jyn514:colors, r=estebankMatthias Krüger-11/+11
use bold magenta instead of bold white for highlighting according to a poll of gay people in my phone, purple is the most popular color to use for highlighting | color | percentage | | ---------- | ---------- | | bold white | 6% | | blue | 14% | | cyan | 26% | | purple | 37% | | magenta | 17% | unfortunately, purple is not supported by 16-color terminals, which rustc apparently wants to support for some reason. until we require support for full 256-color terms (e.g. by doing the same feature detection as we currently do for urls), we can't use it. instead, i have collapsed the purple votes into magenta on the theory that they're close, and also because magenta is pretty. before: ![image](https://github.com/rust-lang/rust/assets/23638587/9a89eee2-8b89-422e-8554-812827bb2a23) after: ![image](https://github.com/rust-lang/rust/assets/23638587/5bf3a917-8a20-4afd-af3e-f9491d0d57f5) other colors for comparison: blue: ![image](https://github.com/rust-lang/rust/assets/23638587/6f199c7b-d598-4009-8ffc-6b7b1d0d1f8c) cyan: ![image](https://github.com/rust-lang/rust/assets/23638587/a77e4fe3-563e-4aa5-ae92-745bb67287d1) purple: ![image](https://github.com/rust-lang/rust/assets/23638587/ffe603fb-d811-4106-95a9-4dd4c955924c) magenta without bolding: ![image](https://github.com/rust-lang/rust/assets/23638587/cf927e5f-8b25-4dc2-b8e7-32905a11a459) r? ``@estebank``
2023-12-10remove redundant importssurechen-7/+3
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-09Rollup merge of #118057 - bvanjoi:fix-118048, r=cjgillotGuillaume Gomez-4/+5
dedup for duplicate suggestions Fixes #118048 An easy fix.
2023-12-08use magenta instead of bold for highlightingjyn-1/+1
according to a poll of gay people in my phone, purple is the most popular color to use for highlighting | color | percentage | | ---------- | ---------- | | bold white | 6% | | blue | 14% | | cyan | 26% | | purple | 37% | | magenta | 17% | unfortunately, purple is not supported by 16-color terminals, which rustc apparently wants to support for some reason. until we require support for full 256-color terms (e.g. by doing the same feature detection as we currently do for urls), we can't use it. instead, i have collapsed the purple votes into magenta on the theory that they're close, and also because magenta is pretty.
2023-12-08Simplify and comment the special-casing for Windows colorsjyn-10/+10
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-68/+36
By making it generic, instead of only for `EmissionGuarantee = ()`, we can use it everywhere.
2023-12-04Remove some unused code, and downgrade some `pub`s.Nicholas Nethercote-44/+6
2023-12-04Avoid `Diagnostic::new_with_code(..., None, ...)`.Nicholas Nethercote-5/+5
`Diagnostic::new` can be used instead.
2023-12-04Always use `G` for `EmissionGuarantee` type variables.Nicholas Nethercote-6/+6
That's what is mostly used. This commit changes a few `EM` and `E` and `T` type variables to `G`.
2023-12-04Inline and remove more `DiagnosticBuilder::new_diagnostic_*` functions.Nicholas Nethercote-83/+28
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-04Inline and remove `DiagnosticBuilder::new_diagnostic_*` functions.Nicholas Nethercote-24/+0
They each have a single call site.
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-04dedup for duplicate suggestionsbohan-4/+5
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-12-02Inline and remove `DiagnosticBuilder::new_diagnostic_fatal`.Nicholas Nethercote-9/+1
It has a single call site.
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-21Fix `clippy::needless_borrow` in the compilerNilstrieb-6/+6
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-21Auto merge of #115691 - jsgf:typed-json-diags, r=est31,dtolnaybors-30/+35
Add `$message_type` field to distinguish json diagnostic outputs Currently the json-formatted outputs have no way to unambiguously determine which kind of message is being output. A consumer can look for specific fields in the json object (eg "message"), but there's no guarantee that in future some other kind of output will have a field of the same name. This PR adds a `"type"` field to add json outputs which can be used to unambiguously determine which kind of output it is. The mapping is: `diagnostic`: regular compiler diagnostics `artifact`: artifact notifications `future_incompat`: Future incompatibility report `unused_extern`: Unused crate warnings/errors This matches the "internally tagged" representation for serde enums.
2023-11-20Update some more cases of "type" -> "$message_type"David Tolnay-1/+2
2023-11-19Remove unnecessary .collect()Esteban Küber-7/+7
2023-11-19Don't sort `span_suggestions`, leave that to callerEsteban Küber-6/+1
2023-11-19When encountering struct fn call literal with private fields, suggest all ↵Esteban Küber-4/+7
builders When encountering code like `Box(42)`, suggest `Box::new(42)` and *all* other associated functions that return `-> Box<T>`.
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-11-14Fix some typoscui fliter-1/+1
Signed-off-by: cui fliter <imcusg@gmail.com>