about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
AgeCommit message (Collapse)AuthorLines
2024-02-14Remove `force_print_diagnostic`.Nicholas Nethercote-19/+24
There are a couple of places where we call `inner.emitter.emit_diagnostic` directly rather than going through `inner.emit_diagnostic`, to guarantee the diagnostic is printed. This feels dubious to me, particularly the bypassing of `TRACK_DIAGNOSTIC`. This commit removes those. - In `print_error_count`, it uses `ForceWarning` instead of `Warning`. - It removes `DiagCtxtInner::failure_note`, because it only has three uses and direct use of `emit_diagnostic` is consistent with other similar locations. - It removes `force_print_diagnostic`, and adds `struct_failure_note`, and updates `print_query_stack` accordingly, which makes it more normal. That location doesn't seem to need forced printing anyway.
2024-02-14Make `struct_span_note` call `struct_note`.Nicholas Nethercote-1/+1
So it follows the same pattern as all the other `struct_span_*` methods.
2024-02-13Remove `good_path_delayed_bug`.Nicholas Nethercote-73/+42
It's only has a single remaining purpose: to ensure that a diagnostic is printed when `trimmed_def_paths` is used. It's an annoying mechanism: weak, with odd semantics, badly named, and gets in the way of other changes. This commit replaces it with a simpler `must_produce_diag` mechanism, getting rid of a diagnostic `Level` along the way.
2024-02-12Rollup merge of #120833 - ↵Matthias Krüger-58/+70
nnethercote:more-internal-emit_diagnostics-cleanups, r=oli-obk More internal emit diagnostics cleanups Miscellaneous improvements. r? ``@oli-obk``
2024-02-12constify a couple thread_local staticsMatthias Krüger-2/+2
2024-02-12Change level used in `print_error_count`.Nicholas Nethercote-2/+2
From `Fatal` to `Error`. It has no functional effect, but `Error` makes more sense and lines up better with the `Warning` level used just above.
2024-02-12Tweak delayed bug mentions.Nicholas Nethercote-3/+3
Now that we have both `delayed_bug` and `span_delayed_bug`, it makes sense to use the generic term "delayed bug" more.
2024-02-12Remove final unwanted `unchecked_error_guaranteed` calls.Nicholas Nethercote-53/+65
Now that error counts can't go up and down due to stashing/stealing, we have a nice property: (err_count > 0) iff (an ErrorGuaranteed has been produced) So we can now record `ErrorGuaranteed`s within `DiagCtxt` and use that in methods like `has_error`, instead of checking that the count is greater than 0 and calling `unchecked_error_guaranteed` to create the `ErrorGuaranteed`. In fact, we can record a `Vec<ErrorGuaranteed>` and use its length to count the number, instead of maintaining a separate count.
2024-02-12Fix inconsistencies in the diagnostic API methods.Nicholas Nethercote-32/+21
- Remove low-value comments about functionality that is obvious. - Add missing `track_caller` attributes -- every method should have one. - Adjust `rustc_lint_diagnostic` attributes. Every method involving a `impl Into<DiagnosticMessage>` or `impl Into<SubdiangnosticMessage>` argument should have one, except for those producing bugs, which aren't user-facing.
2024-02-12Reorder the diagnostic API methods.Nicholas Nethercote-289/+294
The current order is almost perfectly random. This commit puts them into a predictable order in their own impl block, going from the highest level (`Block`) to the lowest (`Expect`). Within each level this is the order: - struct_err, err - struct_span_err, span_err - create_err, emit_err The first one in each pair creates a diagnostic, the second one creates *and* emits a diagnostic. Not every method is present for every level. The diff is messy, but other than moving methods around, the only thing it does is create the new `impl DiagCtxt` block with its own comment.
2024-02-11Rollup merge of #120272 - ↵Matthias Krüger-0/+11
long-long-float:suppress-suggestions-in-derive-macro, r=oli-obk Suppress suggestions in derive macro close #118809 I suppress warnings inside derive macros. For example, the compiler emits following error by a program described in https://github.com/rust-lang/rust/issues/118809#issuecomment-1852256687 with a suggestion that indicates invalid syntax. ``` error[E0308]: `?` operator has incompatible types --> src/main.rs:3:17 | 3 | #[derive(Debug, Deserialize)] | ^^^^^^^^^^^ expected `u32`, found `u64` | = note: `?` operator cannot convert from `u64` to `u32` = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) help: you can convert a `u64` to a `u32` and panic if the converted value doesn't fit | 3 | #[derive(Debug, Deserialize.try_into().unwrap())] | ++++++++++++++++++++ For more information about this error, try `rustc --explain E0308`. error: could not compile `serde_test` (bin "serde_test") due to 2 previous errors ``` In this PR, suggestions to cast are suppressed. ``` error[E0308]: `?` operator has incompatible types --> src/main.rs:3:17 | 3 | #[derive(Debug, Deserialize)] | ^^^^^^^^^^^ expected `u32`, found `u64` | = note: `?` operator cannot convert from `u64` to `u32` = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0308`. error: could not compile `serde_test` (bin "serde_test") due to 2 previous errors ```
2024-02-11Fix to use for looplong-long-float-8/+7
2024-02-10Remove unnecessary `min_specialization` after bootstrapZalathar-1/+1
These crates all needed specialization for `newtype_index!`, which will no longer be necessary when the current nightly eventually becomes the next bootstrap compiler.
2024-02-09Rollup merge of #120828 - nnethercote:fix-stash-steal, r=oli-obkMatthias Krüger-18/+27
Fix `ErrorGuaranteed` unsoundness with stash/steal. When you stash an error, the error count is incremented. You can then use the non-zero error count to get an `ErrorGuaranteed`. You can then steal the error, which decrements the error count. You can then cancel the error. Example code: ``` fn unsound(dcx: &DiagCtxt) -> ErrorGuaranteed { let sp = rustc_span::DUMMY_SP; let k = rustc_errors::StashKey::Cycle; dcx.struct_err("bogus").stash(sp, k); // increment error count on stash let guar = dcx.has_errors().unwrap(); // ErrorGuaranteed from error count > 0 let err = dcx.steal_diagnostic(sp, k).unwrap(); // decrement error count on steal err.cancel(); // cancel error guar // ErrorGuaranteed with no error emitted! } ``` This commit fixes the problem in the simplest way: by not counting stashed errors in `DiagCtxt::{err_count,has_errors}`. However, just doing this without any other changes leads to over 40 ui test failures. Mostly because of uninteresting extra errors (many saying "type annotations needed" when type inference fails), and in a few cases, due to delayed bugs causing ICEs when no normal errors are printed. To fix these, this commit adds `DiagCtxt::stashed_err_count`, and uses it in three places alongside `DiagCtxt::{has_errors,err_count}`. It's dodgy to rely on it, because unlike `DiagCtxt::err_count` it can go up and down. But it's needed to preserve existing behaviour, and at least the three places that need it are now obvious. r? oli-obk
2024-02-09Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwcoMatthias Krüger-0/+2
Invert diagnostic lints. That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted. r? ````@davidtwco````
2024-02-09Fix `ErrorGuaranteed` unsoundness with stash/steal.Nicholas Nethercote-18/+27
When you stash an error, the error count is incremented. You can then use the non-zero error count to get an `ErrorGuaranteed`. You can then steal the error, which decrements the error count. You can then cancel the error. Example code: ``` fn unsound(dcx: &DiagCtxt) -> ErrorGuaranteed { let sp = rustc_span::DUMMY_SP; let k = rustc_errors::StashKey::Cycle; dcx.struct_err("bogus").stash(sp, k); // increment error count on stash let guar = dcx.has_errors().unwrap(); // ErrorGuaranteed from error count > 0 let err = dcx.steal_diagnostic(sp, k).unwrap(); // decrement error count on steal err.cancel(); // cancel error guar // ErrorGuaranteed with no error emitted! } ``` This commit fixes the problem in the simplest way: by not counting stashed errors in `DiagCtxt::{err_count,has_errors}`. However, just doing this without any other changes leads to over 40 ui test failures. Mostly because of uninteresting extra errors (many saying "type annotations needed" when type inference fails), and in a few cases, due to delayed bugs causing ICEs when no normal errors are printed. To fix these, this commit adds `DiagCtxt::stashed_err_count`, and uses it in three places alongside `DiagCtxt::{has_errors,err_count}`. It's dodgy to rely on it, because unlike `DiagCtxt::err_count` it can go up and down. But it's needed to preserve existing behaviour, and at least the three places that need it are now obvious.
2024-02-09Check with overlaps_or_adjacentlong-long-float-4/+7
2024-02-08Fix `span_bug!` backtracesOli Scherer-0/+1
2024-02-08Rollup merge of #120734 - nnethercote:SubdiagnosticMessageOp, r=compiler-errorsMatthias Krüger-5/+8
Add `SubdiagnosticMessageOp` as a trait alias. It avoids a lot of repetition. r? matthewjasper
2024-02-08Add `SubdiagnosticMessageOp` as a trait alias.Nicholas Nethercote-5/+8
It avoids a lot of repetition.
2024-02-07Rename `unchecked_claim_error_was_emitted` as `unchecked_error_guaranteed`.Nicholas Nethercote-5/+5
It's more to-the-point.
2024-02-07Tighten up `ErrorGuaranteed` handling.Nicholas Nethercote-10/+20
- In `emit_producing_error_guaranteed`, only allow `Level::Error`. - In `emit_diagnostic`, only produce `ErrorGuaranteed` for `Level` and `DelayedBug`. (Not `Bug` or `Fatal`. They don't need it, because the relevant `emit` methods abort.) - Add/update various comments.
2024-02-07Remove return value from `emit_stashed_diagnostics`.Nicholas Nethercote-6/+3
It's never used.
2024-02-06Rollup merge of #120575 - nnethercote:simplify-codegen-diag-handling, r=estebankMatthias Krüger-63/+72
Simplify codegen diagnostic handling Some nice improvements. Details in the individual commit logs. r? ````@estebank````
2024-02-06Rollup merge of #120520 - nnethercote:rename-good-path, r=oli-obkMatthias Krüger-123/+134
Some cleanups around diagnostic levels. Plus some refactoring in and around diagnostic levels and emission. Details in the individual commit logs. r? ````@oli-obk````
2024-02-06Invert diagnostic lints.Nicholas Nethercote-0/+2
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-02-06Check in push_suggestionlong-long-float-0/+9
2024-02-05Make `Emitter::emit_diagnostic` consuming.Nicholas Nethercote-63/+72
All the other `emit`/`emit_diagnostic` methods were recently made consuming (e.g. #119606), but this one wasn't. But it makes sense to. Much of this is straightforward, and lots of `clone` calls are avoided. There are a couple of tricky bits. - `Emitter::primary_span_formatted` no longer takes a `Diagnostic` and returns a pair. Instead it takes the two fields from `Diagnostic` that it used (`span` and `suggestions`) as `&mut`, and modifies them. This is necessary to avoid the cloning of `diag.children` in two emitters. - `from_errors_diagnostic` is rearranged so various uses of `diag` occur before the consuming `emit_diagnostic` call.
2024-02-05Rollup merge of #119600 - aDotInTheVoid:comment-fix, r=compiler-errorsMatthias Krüger-1/+2
Remove outdated references to librustc_middle The relevant comment is now in https://github.com/rust-lang/rust/blob/791a53f380d5cf800191f25941c94ace5099876e/compiler/rustc_middle/src/tests.rs#L3-L13
2024-02-05Split `Level::DelayedBug` in two.Nicholas Nethercote-86/+98
The two kinds of delayed bug have quite different semantics so a stronger conceptual separation is nice. (`is_error` is a good example, because the two kinds have different behaviour.) The commit also moves the `DelayedBug` variant after `Error` in `Level`, to reflect the fact that it's weaker than `Error` -- it might trigger an error but also might not. (The pre-existing `downgrade_to_delayed_bug` function also reflects the notion that delayed bugs are lower/after normal errors.) Plus it condenses some of the comments on `Level` into a table, for easier reading, and introduces `can_be_top_or_sub` to indicate which levels can be used in top-level diagnostics vs. subdiagnostics. Finally, it renames `DiagCtxtInner::span_delayed_bugs` as `DiagCtxtInner::delayed_bugs`. The `span_` prefix is unnecessary because some delayed bugs don't have a span.
2024-02-05Refactor `emit_diagnostic`.Nicholas Nethercote-43/+39
- Combine two different blocks involving `diagnostic.level.get_expectation_id()` into one. - Combine several `if`s involving `diagnostic.level` into a single `match`. This requires reordering some of the operations, but this has no functional effect.
2024-02-05Tighten the assertion in `downgrade_to_delayed_bug`.Nicholas Nethercote-1/+1
I.e. `Bug` and `Fatal` level diagnostics are never downgraded.
2024-02-05Make `Diagnostic::is_error` return false for `Level::FailureNote`.Nicholas Nethercote-3/+6
It doesn't affect behaviour, but makes sense with (a) `FailureNote` having `()` as its emission guarantee, and (b) in `Level` the `is_error` levels now are all listed before the non-`is_error` levels.
2024-02-03Rollup merge of #120573 - nnethercote:rm-BorrowckErrors-tainted_by_errors, ↵Matthias Krüger-7/+2
r=oli-obk Remove `BorrowckErrors::tainted_by_errors` This PR removes one of the `tainted_by_errors` occurrences, replacing it with direct use of `ErrorGuaranteed`. r? `@oli-obk`
2024-02-03Use `StringPart` more.Nicholas Nethercote-31/+26
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.