about summary refs log tree commit diff
path: root/compiler/rustc_errors
AgeCommit message (Collapse)AuthorLines
2024-02-03Simplify future breakage control flow.Nicholas Nethercote-6/+6
`emit_future_breakage` calls `self.dcx().take_future_breakage_diagnostics()` and then passes the result to `self.dcx().emit_future_breakage_report(diags)`. This commit removes the first of these and lets `emit_future_breakage_report` do the taking. It also inlines and removes what is left of `emit_future_breakage`, which has a single call site.
2024-02-03Use `DiagnosticArgName` in a few more places.Nicholas Nethercote-1/+1
2024-02-03Remove some unnecessary `clone` calls.Nicholas Nethercote-5/+3
2024-02-03`SilentEmitter::fatal_note` doesn't need to be optional.Nicholas Nethercote-8/+6
2024-02-03`Diagnostic` cleanupsNicholas Nethercote-18/+2
- `emitted_at` isn't used outside the crate. - `code` and `messages` are public fields, so there's no point have trivial getters/setters for them. - `suggestions` is public, so the comment about "functionality on `Diagnostic`" isn't needed.
2024-02-03Remove an out-of-date comment.Nicholas Nethercote-1/+0
`DiagnosticBuilderInner` was removed some time ago.
2024-02-02Inline and remove `DiagnosticBuilder::into_diagnostic`.Nicholas Nethercote-7/+2
It now has a single call site.
2024-02-01Rework `StringPart`.Nicholas Nethercote-21/+17
When there are two possibilities, both of which use a `String`, it's nicer to use a struct than an enum. Especially when mapping the contents into a tuple.
2024-02-01Fit more values into `DiagnosticArgValue::Number`.Nicholas Nethercote-7/+6
It contains an `i128`, but when creating them we convert any number outside the range -100..100 to a string, because Fluent uses an `f64`. It's all a bit strange. This commit changes the `i128` to an `i32`, which fits safely in Fluent's `f64`, and removes the -100..100 range check. This means that only integers outside the range of `i32` will be converted to strings.
2024-02-01Tweak `emit_stashed_diagnostics`.Nicholas Nethercote-2/+1
`take` + `into_iter` + pattern matching is nicer than `drain` + `map` + `collect`.
2024-01-31Don't hash lints differently to non-lints.Nicholas Nethercote-8/+8
`Diagnostic::keys`, which is used for hashing and equating diagnostics, has a surprising behaviour: it ignores children, but only for lints. This was added in #88493 to fix some duplicated diagnostics, but it doesn't seem necessary any more. This commit removes the special case and only four tests have changed output, with additional errors. And those additional errors aren't exact duplicates, they're just similar. For example, in src/tools/clippy/tests/ui/same_name_method.rs we currently have this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ ``` and with this change we also get this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:81:9 | LL | impl T2 for S {} | ^^^^^^^^^^^^^^^^ ``` I think printing this second argument is reasonable, possibly even preferable to hiding it. And the other cases are similar.
2024-01-30Rollup merge of #118533 - chenyukang:yukang-fix-118455, r=petrochenkovGuillaume Gomez-0/+1
Suppress unhelpful diagnostics for unresolved top level attributes Fixes #118455, unresolved top level attribute error didn't imported prelude and already have emitted an error, report builtin macro and attributes error by the way, so `check_invalid_crate_level_attr` in can ignore them. Also fixes #89566, fixes #67107. r? `@petrochenkov`
2024-01-30Remove the second lifetime from `DiagnosticArg`.Nicholas Nethercote-5/+5
Because it's always static. I'm surprised the compiler allowed this unused lifetime without any complaint.
2024-01-30Remove the lifetime from `DiagnosticArgName`.Nicholas Nethercote-8/+4
Because it's always 'static.
2024-01-30Remove `DiagnosticArgName` from `rustc_codegen_ssa`.Nicholas Nethercote-2/+2
It's identical to the one in `rustc_errors`; use that instead. Also remove some `rustc_errors::` qualifiers.
2024-01-30Remove the lifetime from `DiagnosticArgValue`.Nicholas Nethercote-52/+46
Because it's almost always static. This makes `impl IntoDiagnosticArg for DiagnosticArgValue` trivial, which is nice. There are a few diagnostics constructed in `compiler/rustc_mir_build/src/check_unsafety.rs` and `compiler/rustc_mir_transform/src/errors.rs` that now need symbols converted to `String` with `to_string` instead of `&str` with `as_str`, but that' no big deal, and worth it for the simplifications elsewhere.
2024-01-29Supress unhelpful diagnostics for unresolved top level attributesyukang-0/+1
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-41/+84
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-29Sort attributes in `compiler/rustc_errors/src/lib.rs`.Nicholas Nethercote-5/+7
As is already done in `rustc_span` and `rustc_data_structures`.
2024-01-26Fix typoUrgau-1/+1
Co-authored-by: Michael Goulet <michael@errs.io>
2024-01-26Improve handling of numbers in IntoDiagnosticArgUrgau-25/+22
2024-01-25Remove unused featuresclubby789-2/+1
2024-01-23add list of characters to uncommon codepoints lintHTGAzureX1212.-0/+8
2024-01-22Tweak error counting.Nicholas Nethercote-15/+11
We have several methods indicating the presence of errors, lint errors, and delayed bugs. I find it frustrating that it's very unclear which one you should use in any particular spot. This commit attempts to instill a basic principle of "use the least general one possible", because that reflects reality in practice -- `has_errors` is the least general one and has by far the most uses (esp. via `abort_if_errors`). Specifics: - Add some comments giving some usage guidelines. - Prefer `has_errors` to comparing `err_count` to zero. - Remove `has_errors_or_span_delayed_bugs` because it's a weird one: in the cases where we need to count delayed bugs, we should really be counting lint errors as well. - Rename `is_compilation_going_to_fail` as `has_errors_or_lint_errors_or_span_delayed_bugs`, for consistency with `has_errors` and `has_errors_or_lint_errors`. - Change a few other `has_errors_or_lint_errors` calls to `has_errors`, as per the "least general" principle. This didn't turn out to be as neat as I hoped when I started, but I think it's still an improvement.
2024-01-22Count "unused extern" errors as lints rather than normal errors.Nicholas Nethercote-1/+1
2024-01-22Clarify comments about diagnostic count fields.Nicholas Nethercote-6/+6
2024-01-14Rework how diagnostic lints are stored.Nicholas Nethercote-85/+74
`Diagnostic::code` has the type `DiagnosticId`, which has `Error` and `Lint` variants. Plus `Diagnostic::is_lint` is a bool, which should be redundant w.r.t. `Diagnostic::code`. Seems simple. Except it's possible for a lint to have an error code, in which case its `code` field is recorded as `Error`, and `is_lint` is required to indicate that it's a lint. This is what happens with `derive(LintDiagnostic)` lints. Which means those lints don't have a lint name or a `has_future_breakage` field because those are stored in the `DiagnosticId::Lint`. It's all a bit messy and confused and seems unintentional. This commit: - removes `DiagnosticId`; - changes `Diagnostic::code` to `Option<String>`, which means both errors and lints can straightforwardly have an error code; - changes `Diagnostic::is_lint` to `Option<IsLint>`, where `IsLint` is a new type containing a lint name and a `has_future_breakage` bool, so all lints can have those, error code or not.
2024-01-14Reformat `struct_span_code_err!`.Nicholas Nethercote-5/+1
2024-01-13Don't consider delayed bugs for `-Ztreat-err-as-bug`.Nicholas Nethercote-41/+23
`-Ztreat-err-as-bug` treats normal errors and delayed bugs equally, which can lead to some really surprising results. This commit changes `-Ztreat-err-as-bug` so it ignores delayed bugs, unless they get promoted to proper bugs and are printed. This feels to me much simpler and more logical. And it simplifies the implementation: - The `-Ztreat-err-as-bug` check is removed from in `DiagCtxt::{delayed_bug,span_delayed_bug}`. - `treat_err_as_bug` doesn't need to count delayed bugs. - The `-Ztreat-err-as-bug` panic message is simpler, because it doesn't have to mention delayed bugs. Output of delayed bugs is now more consistent. They're always printed the same way. Previously when they triggered `-Ztreat-err-as-bug` they would be printed slightly differently, via `span_bug` in `span_delayed_bug` or `delayed_bug`. A minor behaviour change: the "no errors encountered even though `span_delayed_bug` issued" printed before delayed bugs is now a note rather than a bug. This is done so it doesn't get counted as an error that might trigger `-Ztreat-err-as-bug`, which would be silly. This means that if you use `-Ztreat-err-as-bug=1` and there are no normal errors but there are delayed bugs, the first delayed bug will be shown (and the panic will happen after it's printed). Also, I have added a second note saying "those delayed bugs will now be shown as internal compiler errors". I think this makes it clearer what is happening, because the whole concept of delayed bugs is non-obvious. There are some test changes. - equality-in-canonical-query.rs: Minor output changes, and the error count reduces by one because the "no errors encountered even though `span_delayed_bug` issued" message is no longer counted as an error. - rpit_tait_equality_in_canonical_query.rs: Ditto. - storage-live.rs: The query stack disappears because these delayed bugs are now printed at the end, rather than when they are created. - storage-return.rs, span_delayed_bug.rs: now need `-Zeagerly-emit-delayed-bugs` because they need the delayed bugs emitted immediately to preserve behaviour.
2024-01-12Give me a way to emit all the delayed bugsMichael Goulet-0/+6
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.