about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/diagnostic.rs
AgeCommit message (Collapse)AuthorLines
2025-09-04chore: Remove redundant disjoint spans assertScott Schafer-5/+0
2025-08-24Allow errors to be emitted as fatal during attribute parsingJana Dönszelmann-0/+23
2025-08-22Refactor lint buffering to avoid requiring a giant enumJosh Triplett-1/+11
Lint buffering currently relies on a giant enum `BuiltinLintDiag` containing all the lints that might potentially get buffered. In addition to being an unwieldy enum in a central crate, this also makes `rustc_lint_defs` a build bottleneck: it depends on various types from various crates (with a steady pressure to add more), and many crates depend on it. Having all of these variants in a separate crate also prevents detecting when a variant becomes unused, which we can do with a dedicated type defined and used in the same crate. Refactor this to use a dyn trait, to allow using `LintDiagnostic` types directly. This requires boxing, but all of this is already on the slow path (emitting an error). Because the existing `BuiltinLintDiag` requires some additional types in order to decorate some variants, which are only available later in `rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn LintDiagnostic` case and the `BuiltinLintDiag` case.
2025-08-20Move `IntoDiagArg` earlier in the dependency chainsJosh Triplett-51/+1
`rustc_errors` depends on numerous crates, solely to implement its `IntoDiagArg` trait on types from those crates. Many crates depend on `rustc_errors`, and it's on the critical path. We can't swap things around to make all of those crates depend on `rustc_errors` instead, because `rustc_errors` would end up in dependency cycles. Instead, move `IntoDiagArg` into `rustc_error_messages`, which has far fewer dependencies, and then have most of these crates depend on `rustc_error_messages`. This allows `rustc_errors` to drop dependencies on several crates, including the large `rustc_target`. (This doesn't fully reduce dependency chains yet, as `rustc_errors` still depends on `rustc_hir` which depends on `rustc_target`. That will get fixed in a subsequent commit.)
2025-08-14Rollup merge of #137872 - estebank:extra-vert, r=compiler-errorsJakub Beránek-1/+1
Include whitespace in "remove |" suggestion and make it hidden Tweak error rendering of patterns with an extra `|` on either end. Built on #137409. Only last commit is relevant. ? ``@compiler-errors``
2025-08-10Point at the `Fn()` or `FnMut()` bound that coerced a closure, which caused ↵Esteban Küber-3/+4
a move error When encountering a move error involving a closure because the captured value isn't `Copy`, and the obligation comes from a bound on a type parameter that requires `Fn` or `FnMut`, we point at it and explain that an `FnOnce` wouldn't cause the move error. ``` error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure --> f111.rs:15:25 | 14 | fn do_stuff(foo: Option<Foo>) { | --- ----------- move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait | | | captured outer variable 15 | require_fn_trait(|| async { | -- ^^^^^ `foo` is moved here | | | captured by this `Fn` closure 16 | if foo.map_or(false, |f| f.foo()) { | --- variable moved due to use in coroutine | help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once --> f111.rs:12:53 | 12 | fn require_fn_trait<F: Future<Output = ()>>(_: impl Fn() -> F) {} | ^^^^^^^^^ help: consider cloning the value if the performance cost is acceptable | 16 | if foo.clone().map_or(false, |f| f.foo()) { | ++++++++ ```
2025-08-07Use `tcx.short_string()` in more diagnosticsEsteban Küber-0/+5
`TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`. We add support for shortening the path of "trait path only". Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem). When we don't actually print out a shortened type we don't need the "use `--verbose`" note. On E0599 show type identity to avoid expanding the receiver's generic parameters. Unify wording on `long_ty_path` everywhere.
2025-08-04Include whitespace in "remove `|`" suggestion and make it hiddenEsteban Küber-1/+1
2025-07-19rename `emit_unless` to `emit_unless_delay`xizheyin-1/+1
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-10Make `Diag::multipart_suggestions` always verboseEsteban Küber-1/+1
2025-07-03refactor: Make -Ztrack-diagnostics emit like a noteScott Schafer-0/+9
2025-06-30linkify CodeSuggestion in doc commentsDan Johnson-2/+2
2025-06-25Add runtime check to avoid overwrite arg easily in diag and store and ↵xizheyin-1/+31
restore snapshot when set subdiag arg Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-27Remove an unnecessary use of `Box::into_inner`.Nicholas Nethercote-1/+1
2025-04-16Move eager translation to a method on `Diag`Jake Goulding-20/+13
This will allow us to eagerly translate messages on a top-level diagnostic, such as a `LintDiagnostic`. As a bonus, we can remove the awkward closure passed into Subdiagnostic and make better use of `Into`.
2025-04-08Remove unnecessary dyn Display in favor of strMichael Goulet-4/+4
2025-04-03Split ExpectationLintId off LevelOli Scherer-4/+17
2025-03-07compiler: Use size_of from the prelude instead of importedThalia Archibald-1/+1
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-02-25add doc comment detailEsteban Küber-0/+6
2025-02-25Teach structured errors to display short `Ty`Esteban Küber-3/+3
Make it so that every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to. ``` error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)`` --> long.rs:7:5 | 6 | fn foo(x: D) { //~ `x` has type `(... | - `x` has type `((..., ..., ..., ...), ..., ..., ...)` 7 | x(); //~ ERROR expected function, found `(... | ^-- | | | call expression requires function | = note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt' = note: consider using `--verbose` to print the full type name to the console ```
2025-02-02Rollup merge of #136415 - estebank:highlight-clarification, r=compiler-errorsMatthias Krüger-5/+15
Highlight clarifying information in "expected/found" error When the expected and found types have the same textual representation, we add clarifying in parentheses. We now visually highlight it in the output. Detect a corner case where the clarifying information would be the same for both types and skip it, as it doesn't add anything useful. ![Screenshot of the rustc highlighted output on the terminal](https://github.com/user-attachments/assets/aa4b9433-5332-4941-b2c2-1a43e5cadff7)
2025-02-02Highlight clarifying information in "expected/found" errorEsteban Küber-5/+15
When the expected and found types have the same textual representation, we add clarifying in parentheses. We now visually highlight it in the output. Detect a corner case where the clarifying information would be the same for both types and skip it, as it doesn't add anything useful.
2025-01-31Rework "long type names" printing logicEsteban Küber-0/+31
Make it so more type-system types can be printed in a shortened version (like `Predicate`s). Centralize printing the information about the "full type name path". Make the "long type path" for the file where long types are written part of `Diag`, so that it becomes easier to keep track of it, and ensure it will always will be printed out last in the diagnostic by making its addition to the output implicit. Tweak the shortening of types in "expected/found" labels. Remove dead file `note.rs`.
2025-01-11fix `it's` -> `its` in doc commentYotam Ofek-1/+1
2024-12-31Convert some Into impls into From implsMichael Goulet-3/+3
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-2/+2
2024-09-12Implement a Method to Seal `DiagInner`'s SuggestionsVeera-12/+24
2024-09-11clippy::useless_conversionMichael Goulet-2/+2
2024-09-06Check AttrId for expectations.Camille GILLOT-22/+2
2024-09-02Rollup merge of #129875 - Sajjon:sajjon_fix_typos_batch_1, ↵Matthias Krüger-1/+1
r=compiler-errors,jieyouxu chore: Fix typos in 'compiler' (batch 1) Batch 1/3: Fixes typos in `compiler` (See [issue](https://github.com/rust-lang/rust/issues/129874) tracking all PRs with typos fixes)
2024-09-02chore: Fix typos in 'compiler' (batch 1)Alexander Cyon-1/+1
2024-08-31Remove attr_id from stable lint ids.Camille GILLOT-1/+1
2024-08-31Use AttrId key for unstable<->stable expectation map.Camille GILLOT-12/+7
2024-08-27Add `warn(unreachable_pub)` to `rustc_errors`.Nicholas Nethercote-1/+1
2024-08-09use stable sort to sort multipart diagnosticsFolkert-2/+2
2024-08-06Maintain highlighting in `note` and `help` even when they have a spanEsteban Küber-0/+21
2024-07-29Reformat `use` declarations.Nicholas Nethercote-13/+14
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-26Automatically taint InferCtxt when errors are emittedOli Scherer-1/+1
2024-06-26Restrict diagnostic context lifetime of InferCtxt to itself instead of TyCtxtOli Scherer-0/+5
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-5/+2
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-9/+10
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-2/+0
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-15Fix the dedup error because of spans from suggestionyukang-1/+1
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-0/+1
2024-04-29Remove `extern crate rustc_macros` from numerous crates.Nicholas Nethercote-0/+1
2024-04-21Pass translation closure to add_to_diag_with() as referenceXiretza-3/+3
2024-04-20Print note with closure signature on type mismatchDaniel Sedlak-1/+1
2024-03-14Make `SubdiagMessageOp` well-formedMichael Goulet-1/+2
2024-03-11Rename `DecorateLint` as `LintDiagnostic`.Nicholas Nethercote-2/+2
To match `derive(LintDiagnostic)`.