about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2024-05-23Remove `DelayDm`León Orell Valerian Liehr-3/+3
With the removal of `LintDiagnostic::msg` / the `msg` param from lint diag APIs, primary messages for lint diags are always constructed lazily inside decorator fns rendering this wrapper type unused / useless.
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-3/+1
2024-04-29Remove `extern crate rustc_macros` from numerous crates.Nicholas Nethercote-3/+1
2024-04-25Format stash message correctlyMichael Goulet-2/+2
2024-04-23Rollup merge of #124218 - Xiretza:subsubdiagnostics, r=davidtwcoLeón Orell Valerian Liehr-18/+15
Allow nesting subdiagnostics in #[derive(Subdiagnostic)]
2024-04-22Stabilize generic `NonZero`.Markus Reiter-1/+0
2024-04-21Move "elided lifetime in path" to subdiagnostic structXiretza-18/+15
This requires nested subdiagnostics.
2024-04-18Simplify `static_assert_size`s.Nicholas Nethercote-2/+2
We want to run them on all 64-bit platforms.
2024-04-03Rollup merge of #123401 - Zalathar:assert-size-aarch64, r=fmeaseJacob Pratt-2/+2
Check `x86_64` size assertions on `aarch64`, too (Context: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Checking.20size.20assertions.20on.20aarch64.3F) Currently the compiler has around 30 sets of `static_assert_size!` for various size-critical data structures (e.g. various IR nodes), guarded by `#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]`. (Presumably this cfg avoids having to maintain separate size values for 32-bit targets and unusual 64-bit targets. Apparently it may have been necessary before the i128/u128 alignment changes, too.) This is slightly incovenient for people on aarch64 workstations (e.g. Macs), because the assertions normally aren't checked until we push to a PR. So this PR adds `aarch64` to the `#[cfg(..)]` guarding all of those assertions in the compiler. --- Implemented with a simple find/replace. Verified by manually inspecting each `static_assert_size!` in `compiler/`, and checking that either the replacement succeeded, or adding aarch64 wouldn't have been appropriate.
2024-04-03Rollup merge of #121595 - strottos:issue_116615, r=compiler-errorsMatthias Krüger-0/+33
Better reporting on generic argument mismatchs This allows better reporting as per issue #116615 . If you have a function: ``` fn foo(a: T, b: T) {} ``` and call it like so: ``` foo(1, 2.) ``` it'll give improved error reported similar to the following: ``` error[E0308]: mismatched types --> generic-mismatch-reporting-issue-116615.rs:6:12 | 6 | foo(1, 2.); | --- - ^^ expected integer, found floating-point number | | | | | expected argument `b` to be an integer because that argument needs to match the type of this parameter | arguments to this function are incorrect | note: function defined here --> generic-mismatch-reporting-issue-116615.rs:1:4 | 1 | fn foo<T>(a: T, b: T) {} | ^^^ - ---- ---- | | | | | | | this parameter needs to match the integer type of `a` | | `b` needs to match the type of this parameter | `a` and `b` all reference this parameter T ``` Open question, do we need to worry about error message translation into other languages? Not sure what the status of that is in Rust. NB: Needs some checking over and some tests have altered that need sanity checking, but overall this is starting to get somewhere now. Will take out of draft PR status when this has been done, raising now to allow feedback at this stage, probably 90% ready.
2024-04-03Check `x86_64` size assertions on `aarch64`, tooZalathar-2/+2
This makes it easier for contributors on aarch64 workstations (e.g. Macs) to notice when these assertions have been violated.
2024-03-24Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, ↵Matthias Krüger-1/+7
r=davidtwco conditionally ignore fatal diagnostic in the SilentEmitter This change is primarily meant to allow rustfmt to ignore all diagnostics when using the `SilentEmitter`. Back in #121301 the `SilentEmitter` was shared between rustc and rustfmt. This changed rustfmt's behavior from ignoring all diagnostic to emitting fatal diagnostics, which lead to https://github.com/rust-lang/rustfmt/issues/6109. These changes allow rustfmt to maintain its previous behaviour when using the `SilentEmitter`, while allowing rustc code to still emit fatal diagnostics.
2024-03-20step cfgsMark Rousskov-1/+0
2024-03-19conditionally ignore fatal diagnostic in the SilentEmitterYacin Tmimi-1/+7
This change is primarily meant to allow rustfmt to ignore all diagnostics when using the `SilentEmitter`. Back in PR 121301 the `SilentEmitter` was shared between rustc and rustfmt. This changed rustfmt's behavior from ignoring all diagnostic to emitting fatal diagnostics. These changes allow rustfmt to maintain it's previous behaviour when using the SilentEmitter, while allowing rustc code to still emit fatal diagnostics.
2024-03-15Refactored a few bits:Steven Trotter-1/+34
- Firstly get all the information about generics matching out of the HIR - Secondly the labelling for the function is more coherent now - Lastly a few error message improvements
2024-03-15Added ability to report on generic argument mismatch betterSteven Trotter-1/+1
Needs some checking over and some tests have altered that need sanity checking, but overall this is starting to get somewhere now.
2024-03-14Rollup merge of #120699 - nnethercote:rm-useless-TRACK_DIAGNOSTIC-calls, ↵Matthias Krüger-70/+92
r=oli-obk Document `TRACK_DIAGNOSTIC` calls. r? ```````@cjgillot```````
2024-03-12Rollup merge of #122194 - oli-obk:stash_delay_bug, r=nnethercoteMatthias Krüger-7/+4
Enable creating backtraces via -Ztreat-err-as-bug when stashing errors r? `@nnethercote` Otherwise I can't debug stashed errors because I can't find their source
2024-03-11Rollup merge of #122299 - compiler-errors:bt-for-must-diag, r=nnethercoteJubilee-8/+14
Store backtrace for `must_produce_diag` This makes it significantly easier to debug a `must_produce_diag` ICE, since we have no other way to know where the heck the bug originates from. Backtrace rendering kinda sucks right now since we're just printing it in the panic message; happy to apply some suggestions to make it prettier or reuse other bug printing machinery, but also don't want to iterate too much on the rendering since this really is just for debug purposes. r? nnethercote
2024-03-11Enable creating backtraces via -Ztreat-err-as-bug when stashing errorsOli Scherer-7/+4
2024-03-10Store backtrace for must_produce_diagMichael Goulet-8/+14
2024-03-11Rename `DecorateLint` as `LintDiagnostic`.Nicholas Nethercote-2/+2
To match `derive(LintDiagnostic)`.
2024-03-11Rename `AddToDiagnostic` as `Subdiagnostic`.Nicholas Nethercote-3/+3
To match `derive(Subdiagnostic)`. Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-11Rename `IntoDiagnostic` as `Diagnostic`.Nicholas Nethercote-22/+19
To match `derive(Diagnostic)`. Also rename `into_diagnostic` as `into_diag`.
2024-03-11Rename `IntoDiagnosticArg` as `IntoDiagArg`.Nicholas Nethercote-1/+1
Also rename `into_diagnostic_arg` as `into_diag_arg`, and `NotIntoDiagnosticArg` as `NotInotDiagArg`.
2024-03-06Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnostic-lint, ↵Matthias Krüger-16/+24
r=davidtwco Rework `untranslatable_diagnostic` lint Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This PR changes it to check calls to any function with an `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. It also lets us add `#[rustc_lint_diagnostics]` to a number of functions that don't have an `impl Into<{D,Subd}iagnosticMessage>`, such as `Diag::span`. r? ``@davidtwco``
2024-03-05errors: share `SilentEmitter` between rustc and rustfmtDavid Wood-23/+72
Signed-off-by: David Wood <david@davidtw.co>
2024-03-05Change message type in bug functions.Nicholas Nethercote-16/+24
From `impl Into<DiagnosticMessage>` to `impl Into<Cow<'static, str>>`. Because these functions don't produce user-facing output and we don't want their strings to be translated.
2024-03-05Rename `SubdiagnosticMessageOp` as `SubdiagMessageOp`.Nicholas Nethercote-1/+1
2024-03-05Rename `SubdiagnosticMessage` as `SubdiagMessage`.Nicholas Nethercote-8/+8
2024-03-05Rename `DiagnosticMessage` as `DiagMessage`.Nicholas Nethercote-34/+34
2024-03-01Make the `match` in `emit_diagnostic` complete.Nicholas Nethercote-18/+23
This match is complex enough that it's a good idea to enumerate every variant. This also means `can_be_top_or_sub` can just be `can_be_subdiag`.
2024-03-01Add comments about `TRACK_DIAGNOSTIC` use.Nicholas Nethercote-1/+16
Also add an assertion for the levels allowed with `has_future_breakage`.
2024-03-01Move `Expect`/`ForceWarning` handling into the `match`.Nicholas Nethercote-15/+17
Note that `self.suppressed_expected_diag` is no longer set for `ForceWarning`, which is good. Nor is `TRACK_DIAGNOSTIC` called for `Allow`, which is also good.
2024-03-01Reorder `has_future_breakage` handling.Nicholas Nethercote-8/+8
This will enable additional refactorings.
2024-03-01Move `DelayedBug` handling into the `match`.Nicholas Nethercote-23/+28
It results in a tiny bit of duplication (another `self.treat_next_err_as_bug()` condition) but I think it's worth it to get more code into the main `match`.
2024-03-01Inline and remove `Level::get_diagnostic_id`.Nicholas Nethercote-10/+3
It has a single call site, and this will enable subsequent refactorings.
2024-03-01Give `TRACK_DIAGNOSTIC` a return value.Nicholas Nethercote-11/+13
This means `DiagCtxtInner::emit_diagnostic` can return its result directly, rather than having to modify a local variable.
2024-03-01Handle stashing of delayed bugs.Nicholas Nethercote-11/+25
By just emitting them immediately, because it does happen in practice, when errors are downgraded to delayed bugs. We already had one case in `lint.rs` where we handled this at the callsite. This commit changes things so it's handled within `stash_diagnostic` instead, because #121812 identified a second case, and it's possible there are more. Fixes #121812.
2024-03-01Remove unnecessary `Level::` qualifiers.Nicholas Nethercote-7/+7
We have `use Level::*;` in this file.
2024-02-29Rollup merge of #121783 - nnethercote:emitter-cleanups, r=oli-obkGuillaume Gomez-16/+9
Emitter cleanups Some cleanups I made when reading emitter code. In particular, `HumanEmitter` and `JsonEmitter` have gone from three constructors to one. r? `@oli-obk`
2024-02-29Rollup merge of #121669 - nnethercote:count-stashed-errs-again, r=estebankGuillaume Gomez-65/+154
Count stashed errors again Stashed diagnostics are such a pain. Their "might be emitted, might not" semantics messes with lots of things. #120828 and #121206 made some big changes to how they work, improving some things, but still leaving some problems, as seen by the issues caused by #121206. This PR aims to fix all of them by restricting them in a way that eliminates the "might be emitted, might not" semantics while still allowing 98% of their benefit. Details in the individual commit logs. r? `@oli-obk`
2024-02-29Rename `DiagCtxt::with_emitter` as `DiagCtxt::new`.Nicholas Nethercote-1/+1
Because it's now the only constructor.
2024-02-29Inline and remove `DiagCtxt::with_tty_emitter`Nicholas Nethercote-9/+2
It only has two call sites, and one of those doesn't set the source map.
2024-02-29Minor visibility and formatting improvements.Nicholas Nethercote-6/+6
2024-02-29Reinstate `emit_stashed_diagnostics` in `DiagCtxtInner::drop`.Nicholas Nethercote-4/+6
I removed it in #121206 because I thought thought it wasn't necessary. But then I had to add an `emit_stashed_diagnostics` call elsewhere in rustfmt to avoid the assertion failure (which took two attempts to get right, #121487 and #121615), and now there's an assertion failure in clippy as well (https://github.com/rust-lang/rust-clippy/issues/12364). So this commit just reinstates the call in `DiagCtxtInner::drop`. It also reverts the rustfmt changes from #121487 and #121615, though it keeps the tests added for those PRs.
2024-02-29Overhaul how stashed diagnostics work, again.Nicholas Nethercote-62/+149
Stashed errors used to be counted as errors, but could then be cancelled, leading to `ErrorGuaranteed` soundness holes. #120828 changed that, closing the soundness hole. But it introduced other difficulties because you sometimes have to account for pending stashed errors when making decisions about whether errors have occured/will occur and it's easy to overlook these. This commit aims for a middle ground. - Stashed errors (not warnings) are counted immediately as emitted errors, avoiding the possibility of forgetting to consider them. - The ability to cancel (or downgrade) stashed errors is eliminated, by disallowing the use of `steal_diagnostic` with errors, and introducing the more restrictive methods `try_steal_{modify,replace}_and_emit_err` that can be used instead. Other things: - `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both return `Option<ErrorGuaranteed>`, which enables the removal of two `delayed_bug` calls and one `Ty::new_error_with_message` call. This is possible because we store error guarantees in `DiagCtxt::stashed_diagnostics`. - Storing the guarantees also saves us having to maintain a counter. - Calls to the `stashed_err_count` method are no longer necessary alongside calls to `has_errors`, which is a nice simplification, and eliminates two more `span_delayed_bug` calls and one FIXME comment. - Tests are added for three of the four fixed PRs mentioned below. - `issue-121108.rs`'s output improved slightly, omitting a non-useful error message. Fixes #121451. Fixes #121477. Fixes #121504. Fixes #121508.
2024-02-29Refactor `DiagCtxtInner::flush_delayed`.Nicholas Nethercote-21/+21
This commit: - Moves the ICE file create/open outside the loop. (Redoing it on every loop iteration works, but is really weird.) - Moves the explanatory note emission above the loop, which removes the need for the `enumerate` call. - Introduces a `decorate` local.
2024-02-28Rename `DiagnosticStyledString` as `DiagStyledString`.Nicholas Nethercote-2/+2
2024-02-28Rename `DiagnosticSymbolList` as `DiagSymbolList`.Nicholas Nethercote-1/+1