about summary refs log tree commit diff
path: root/compiler/rustc_errors
AgeCommit message (Collapse)AuthorLines
2024-01-12Good path bugs are just a flavor of delayed bugMichael Goulet-29/+44
2024-01-12Avoid repetition in `flush_delayed` calls.Nicholas Nethercote-15/+20
There are two places that handle normal delayed bugs. This commit factors out some repeated code. Also, we can use `std::mem::take` instead of `std::mem::replace`.
2024-01-11Rollup merge of #119853 - klensy:rustfmt-ignore, r=cuviperMatthias Krüger-2/+3
rustfmt.toml: don't ignore just any tests path, only root one Previously ignored any `tests` path, now only /tests at repo root. For reference, https://git-scm.com/docs/gitignore#_pattern_format
2024-01-11Rollup merge of #119841 - nnethercote:rm-DiagnosticBuilder-buffer, r=oli-obkMatthias Krüger-43/+14
Remove `DiagnosticBuilder::buffer` `DiagnosticBuilder::buffer` doesn't do much, and part of what it does (for `-Ztreat-err-as-bug`) it shouldn't. This PR strips it back, replaces its uses, and finally removes it, making a few cleanups in the vicinity along the way. r? ``@oli-obk``
2024-01-11Rollup merge of #119448 - klensy:annotate-snippets-0.10, r=davidtwcoMatthias Krüger-9/+4
annotate-snippets: update to 0.10 Ports `annotate-snippets` to 0.10, temporary dupes versions; other crates left that depends on 0.9 is `ui_test` and `rustfmt`.
2024-01-11apply fmtklensy-2/+3
2024-01-11Remove `DiagnosticBuilder::buffer`.Nicholas Nethercote-5/+0
All its uses have been removed.
2024-01-11Stop using `DiagnosticBuilder::buffer` in `BorrowckErrors`.Nicholas Nethercote-1/+1
But we can't easily switch from `Vec<Diagnostic>` to `Vec<DiagnosticBuilder<G>>` because there's a mix of errors and warnings which result in different `G` types. So we must make `DiagnosticBuilder::into_diagnostic` public, but that's ok, and it will get more use in subsequent commits.
2024-01-11Remove `DiagnosticBuilder::into_diagnostic` from `-Ztreat-err-as-bug` ↵Nicholas Nethercote-23/+6
consideration. It seems very wrong to have a `-Ztreat-err-as-bug` check here before the error is even emitted. Once that's done: - `into_diagnostic` is infallible, so its return type doesn't need the `Option`; - the `&'a DiagCtxt` also isn't needed, because only one callsite uses it, and it already have access to it via `self.dcx`; - the comments about dcx disabling buffering are no longer true, this is unconditional now; - and the `debug!` seems unnecessary... the comment greatly overstates its importance because few diagnostics come through `into_diagnostic`, and `-Ztrack-diagnostics` exists anyway.
2024-01-11Move code around.Nicholas Nethercote-3/+4
No point computing `warnings` and `errors` if we're going to return early before they're used.
2024-01-11Use the right level with `-Ztreat-err-as-bug`.Nicholas Nethercote-1/+1
Errors in `DiagCtxtInner::emit_diagnostic` are never set to `Level::Bug`, because the condition never succeeds, because `self.treat_err_as_bug()` is called *before* the error counts are incremented. This commit switches to `self.treat_next_err_as_bug()`, fixing the problem. This changes the error message output to actually say "internal compiler error".
2024-01-11Inline and remove `DiagCtxtInner::bump_{lint_err,err}_count`.Nicholas Nethercote-13/+5
They have one and two call sites respectively, and they just make the code harder to read.
2024-01-11Simplify lint error counting.Nicholas Nethercote-4/+4
Of the error levels satisfying `is_error`, `Level::Error` is the only one that can be a lint, so there's no need to check for it. (And even if it wasn't, it would make more sense to include non-`Error`-but-`is_error` lints under `lint_err_count` than under `err_count`.)
2024-01-11Replace `warn_count`.Nicholas Nethercote-29/+12
There are four functions that adjust error and warning counts: - `stash_diagnostic` (increment) - `steal_diagnostic` (decrement) - `emit_stashed_diagnostics) (decrement) - `emit_diagnostic` (increment) The first three all behave similarly, and only update `warn_count` for forced warnings. But the last one updates `warn_count` for both forced and non-forced warnings. Seems like a bug. How should it be fixed? Well, `warn_count` is only used in one place: `DiagCtxtInner::drop`, where it's part of the condition relating to the printing of `good_path_delayed_bugs`. The intention of that condition seems to be "have any errors been printed?" so this commit replaces `warn_count` with `has_printed`, which is set when printing occurs. This is simpler than all the ahead-of-time incrementing and decrementing.
2024-01-11Move `DiagCtxtInner::deduplicated_warn_count`.Nicholas Nethercote-3/+4
To put it next to a similar field.
2024-01-11Reset `lint_err_count` in `DiagCtxt::reset_err_count`.Nicholas Nethercote-0/+1
It's missing but should obviously be included.
2024-01-11Change how `force-warn` lint diagnostics are recorded.Nicholas Nethercote-25/+28
`is_force_warn` is only possible for diagnostics with `Level::Warning`, but it is currently stored in `Diagnostic::code`, which every diagnostic has. This commit: - removes the boolean `DiagnosticId::Lint::is_force_warn` field; - adds a `ForceWarning` variant to `Level`. Benefits: - The common `Level::Warning` case now has no arguments, replacing lots of `Warning(None)` occurrences. - `rustc_session::lint::Level` and `rustc_errors::Level` are more similar, both having `ForceWarning` and `Warning`.
2024-01-11Rename `TRACK_DIAGNOSTICS` as `TRACK_DIAGNOSTIC`.Nicholas Nethercote-4/+4
Because the values put into it are functions named `track_diagnostic` and `default_track_diagnostic`.
2024-01-10Add missing `DiagnosticBuilder::eager_diagnostic` method.Nicholas Nethercote-1/+5
This lets us avoid the use of `DiagnosticBuilder::into_diagnostic` in miri, when then means that `DiagnosticBuilder::into_diagnostic` can become private, being now only used by `stash` and `buffer`.
2024-01-10Rename consuming chaining methods on `DiagnosticBuilder`.Nicholas Nethercote-64/+64
In #119606 I added them and used a `_mv` suffix, but that wasn't great. A `with_` prefix has three different existing uses. - Constructors, e.g. `Vec::with_capacity`. - Wrappers that provide an environment to execute some code, e.g. `with_session_globals`. - Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`. The third case is exactly what we want, so this commit changes `DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`. Thanks to @compiler-errors for the suggestion.
2024-01-10Add `DiagCtxt::delayed_bug`.Nicholas Nethercote-7/+11
We have `span_delayed_bug` and often pass it a `DUMMY_SP`. This commit adds `delayed_bug`, which matches pairs like `err`/`span_err` and `warn`/`span_warn`.
2024-01-10Rename `{create,emit}_warning` as `{create,emit}_warn`.Nicholas Nethercote-3/+3
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`, all of which use an abbreviated form.
2024-01-10Rename `struct_span_err!` as `struct_span_code_err!`.Nicholas Nethercote-1/+1
Because it takes an error code after the span. This avoids the confusing overlap with the `DiagCtxt::struct_span_err` method, which doesn't take an error code.
2024-01-10Fix incorrect comment.Nicholas Nethercote-1/+1
2024-01-09Remove `-Zdont-buffer-diagnostics`.Nicholas Nethercote-5/+1
It was added in #54232. It seems like it was aimed at NLL development, which is well in the past. Also, it looks like `-Ztreat-err-as-bug` can be used to achieve the same effect. So it doesn't seem necessary.
2024-01-08Remove `{DiagCtxt,DiagCtxtInner}::emit_diagnostic_without_consuming`.Nicholas Nethercote-23/+7
They are no longer used, because `{DiagCtxt,DiagCtxtInner}::emit_diagnostic` are used everywhere instead. This also means `track_diagnostic` can become consuming.
2024-01-08Remove `DiagnosticBuilderState`.Nicholas Nethercote-141/+73
Currently it's used for two dynamic checks: - When a diagnostic is emitted, has it been emitted before? - When a diagnostic is dropped, has it been emitted/cancelled? The first check is no longer need, because `emit` is consuming, so it's impossible to emit a `DiagnosticBuilder` twice. The second check is still needed. This commit replaces `DiagnosticBuilderState` with a simpler `Option<Box<Diagnostic>>`, which is enough for the second check: functions like `emit` and `cancel` can take the `Diagnostic` and then `drop` can check that the `Diagnostic` was taken. The `DiagCtxt` reference from `DiagnosticBuilderState` is now stored as its own field, removing the need for the `dcx` method. As well as making the code shorter and simpler, the commit removes: - One (deprecated) `ErrorGuaranteed::unchecked_claim_error_was_emitted` call. - Two `FIXME(eddyb)` comments that are no longer relevant. - The use of a dummy `Diagnostic` in `into_diagnostic`. Nice!
2024-01-08Make `emit_producing_{guarantee,nothing}` consuming.Nicholas Nethercote-9/+9
This is now possible, thanks to changes in previous commits.
2024-01-08Remove `DiagnosticBuilder::delay_as_bug_without_consuming`.Nicholas Nethercote-7/+0
The existing uses are replaced in one of three ways. - In a function that also has calls to `emit`, just rearrange the code so that exactly one of `delay_as_bug` or `emit` is called on every path. - In a function returning a `DiagnosticBuilder`, use `downgrade_to_delayed_bug`. That's good enough because it will get emitted later anyway. - In `unclosed_delim_err`, one set of errors is being replaced with another set, so just cancel the original errors.
2024-01-08Remove `DiagnosticBuilder::emit_without_consuming`.Nicholas Nethercote-7/+1
A nice cleanup: it's now impossible to directly emit a `DiagnosticBuilder` without consuming it.
2024-01-08Remove all eight `DiagnosticBuilder::*_with_code` methods.Nicholas Nethercote-94/+2
These all have relatively low use, and can be perfectly emulated with a simpler construction method combined with `code` or `code_mv`.
2024-01-08Use chaining in `DiagnosticBuilder` construction.Nicholas Nethercote-73/+34
To avoid the use of a mutable local variable, and because it reads more nicely.
2024-01-08Make `DiagnosticBuilder::emit` consuming.Nicholas Nethercote-93/+108
This works for most of its call sites. This is nice, because `emit` very much makes sense as a consuming operation -- indeed, `DiagnosticBuilderState` exists to ensure no diagnostic is emitted twice, but it uses runtime checks. For the small number of call sites where a consuming emit doesn't work, the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will be removed in subsequent commits.) Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes consuming, while `delay_as_bug_without_consuming` is added (which will also be removed in subsequent commits.) All this requires significant changes to `DiagnosticBuilder`'s chaining methods. Currently `DiagnosticBuilder` method chaining uses a non-consuming `&mut self -> &mut Self` style, which allows chaining to be used when the chain ends in `emit()`, like so: ``` struct_err(msg).span(span).emit(); ``` But it doesn't work when producing a `DiagnosticBuilder` value, requiring this: ``` let mut err = self.struct_err(msg); err.span(span); err ``` This style of chaining won't work with consuming `emit` though. For that, we need to use to a `self -> Self` style. That also would allow `DiagnosticBuilder` production to be chained, e.g.: ``` self.struct_err(msg).span(span) ``` However, removing the `&mut self -> &mut Self` style would require that individual modifications of a `DiagnosticBuilder` go from this: ``` err.span(span); ``` to this: ``` err = err.span(span); ``` There are *many* such places. I have a high tolerance for tedious refactorings, but even I gave up after a long time trying to convert them all. Instead, this commit has it both ways: the existing `&mut self -> Self` chaining methods are kept, and new `self -> Self` chaining methods are added, all of which have a `_mv` suffix (short for "move"). Changes to the existing `forward!` macro lets this happen with very little additional boilerplate code. I chose to add the suffix to the new chaining methods rather than the existing ones, because the number of changes required is much smaller that way. This doubled chainging is a bit clumsy, but I think it is worthwhile because it allows a *lot* of good things to subsequently happen. In this commit, there are many `mut` qualifiers removed in places where diagnostics are emitted without being modified. In subsequent commits: - chaining can be used more, making the code more concise; - more use of chaining also permits the removal of redundant diagnostic APIs like `struct_err_with_code`, which can be replaced easily with `struct_err` + `code_mv`; - `emit_without_diagnostic` can be removed, which simplifies a lot of machinery, removing the need for `DiagnosticBuilderState`.
2024-01-08Remove `Clone` impl for `DiagnosticBuilder`.Nicholas Nethercote-1/+5
It seems like a bad idea, just asking for diagnostics to be emitted multiple times.
2024-01-07annotate-snippets: update to 0.10klensy-9/+4
2024-01-05Remove outdated references to `librustc_middle`.Alona Enraght-Moony-1/+2
2024-01-05Rollup merge of #119601 - nnethercote:Emitter-cleanups, r=oli-obkMichael Goulet-19/+21
`Emitter` cleanups Some improvements I found while looking at this code. r? `@oli-obk`
2024-01-05Rollup merge of #119567 - nnethercote:rm-Zreport-delayed-bugs, r=oli-obkMichael Goulet-13/+3
Remove `-Zreport-delayed-bugs`. It's not used within the repository in any way (e.g. in tests), and doesn't seem useful. It was added in #52568. r? ````@oli-obk````
2024-01-05Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errorsMichael Goulet-107/+69
Cleanup error handlers: round 5 More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171. r? ````@compiler-errors````
2024-01-05Add some comments to `Emitter`.Nicholas Nethercote-3/+5
There are three functions only used for the JSON format.
2024-01-05Rename `AnnotateSnippetEmitterWriter` as `AnnotateSnippetEmitter`.Nicholas Nethercote-4/+4
For consistency with other `Emitter` impls.
2024-01-05Rename `EmitterWriter` as `HumanEmitter`.Nicholas Nethercote-12/+12
For consistency with other `Emitter` impls, such as `JsonEmitter`, `SilentEmitter`, `SharedEmitter`, etc.
2024-01-04Remove `-Zreport-delayed-bugs`.Nicholas Nethercote-13/+3
It's not used within the repository in any way (e.g. in tests), and doesn't seem useful.
2024-01-04Remove `is_lint` field from `Level::Error`.Nicholas Nethercote-22/+14
Because it's redundant w.r.t. `Diagnostic::is_lint`, which is present for every diagnostic level. `struct_lint_level_impl` was the only place that set the `Error` field to `true`, and it's also the only place that calls `Diagnostic::is_lint()` to set the `is_lint` field.
2024-01-04compiler: fix typosvuittont60-1/+1
librustdoc: fix typos
2024-01-04Remove unused `DiagnosticBuilder::struct_almost_fatal`.Nicholas Nethercote-10/+0
`create_almost_fatal` and `emit_almost_fatal` are always used instead.
2024-01-03Fix `forward!` so it doesn't require trailing commas in some cases.Nicholas Nethercote-4/+4
2024-01-03Fix up `forward!` decls.Nicholas Nethercote-32/+16
- Move comments onto corresponding `Diagnostic` methods. - Make formatting more consistent.
2024-01-03Remove forward for `downgrade_to_delayed_bug`.Nicholas Nethercote-8/+1
It's not used, and doesn't quite fit the general pattern. Also, `Diagnostic::downgrade_to_delayed_bug` doesn't need to return `&mut Self` for the same reason.
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-32/+35
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.