about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/errors.rs
AgeCommit message (Collapse)AuthorLines
2025-04-16Move eager translation to a method on `Diag`Jake Goulding-6/+2
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`.
2024-08-27Add `warn(unreachable_pub)` to `rustc_lint`.Nicholas Nethercote-9/+9
2024-08-21Use bool in favor of Option<()> for diagnosticsMichael Goulet-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-2/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-03Fix up comments.Nicholas Nethercote-1/+1
Wrap overly long ones, etc.
2024-04-21Pass translation closure to add_to_diag_with() as referenceXiretza-1/+1
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-05Rename `SubdiagnosticMessageOp` as `SubdiagMessageOp`.Nicholas Nethercote-2/+2
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-4/+2
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-2/+8
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-08Add `SubdiagnosticMessageOp` as a trait alias.Nicholas Nethercote-5/+2
It avoids a lot of repetition.
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-7/+7
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-03Rename some `Diagnostic` setters.Nicholas Nethercote-1/+1
`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.
2023-08-30feat(rustc_lint): make `CheckLintName` respect lint levelWeihang Lo-53/+1
2023-08-24refactor: use references to reduce unnecessary clonesWeihang Lo-20/+20
2023-08-24lint: translate `RenamedOrRemovedLint`Weihang Lo-3/+13
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-1/+1
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-04-17Spelling - compilerJosh Soref-1/+1
* account * achieved * advising * always * ambiguous * analysis * annotations * appropriate * build * candidates * cascading * category * character * clarification * compound * conceptually * constituent * consts * convenience * corresponds * debruijn * debug * debugable * debuggable * deterministic * discriminant * display * documentation * doesn't * ellipsis * erroneous * evaluability * evaluate * evaluation * explicitly * fallible * fulfill * getting * has * highlighting * illustrative * imported * incompatible * infringing * initialized * into * intrinsic * introduced * javascript * liveness * metadata * monomorphization * nonexistent * nontrivial * obligation * obligations * offset * opaque * opportunities * opt-in * outlive * overlapping * paragraph * parentheses * poisson * precisely * predecessors * predicates * preexisting * propagated * really * reentrant * referent * responsibility * rustonomicon * shortcircuit * simplifiable * simplifications * specify * stabilized * structurally * suggestibility * translatable * transmuting * two * unclosed * uninhabited * visibility * volatile * workaround Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-02-22errors: generate typed identifiers in each crateDavid Wood-3/+3
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-01-09refactor: cleanupRejyr-2/+0
2023-01-09migrate: `levels.rs`Rejyr-2/+2
2023-01-09add: `lints` for `errors.rs`Rejyr-1/+3
2023-01-09migrate: `early.rs` and `enum_intrinsics_non_enums.rs`Rejyr-0/+1
2022-10-26Convert all #[suggestion_*] attributes to #[suggestion(style = "...")]Xiretza-1/+1
Using the following command: find compiler/ -type f -name '*.rs' -exec perl -i -gpe \ 's/(#\[\w*suggestion)_(short|verbose|hidden)\(\s*(\S+,)?/\1(\3style = "\2",/g' \ '{}' +
2022-10-23Migrate all diagnosticsNilstrieb-17/+17
2022-10-17lint: use derive moreDavid Wood-23/+2
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10errors: `AddToDiagnostic::add_to_diagnostic_with`David Wood-3/+12
`AddToDiagnostic::add_to_diagnostic_with` is similar to the previous `AddToDiagnostic::add_to_diagnostic` but takes a function that can be used by the caller to modify diagnostic messages originating from the subdiagnostic (such as performing translation eagerly). `add_to_diagnostic` now just calls `add_to_diagnostic_with` with an empty closure. Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-21FIX - adopt new Diagnostic naming in newly migrated modulesJhonny Bill Mena-1/+1
FIX - ambiguous Diagnostic link in docs UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic [Gardening] FIX - formatting via `x fmt` FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way DELETE - unneeded allow attributes in Handler method FIX - broken test FIX - Rebase conflict UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21UPDATE - rename SessionSubdiagnostic macro to SubdiagnosticJhonny Bill Mena-2/+2
Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21UPDATE - rename DiagnosticHandler macro to DiagnosticJhonny Bill Mena-9/+9
2022-09-21UPDATE - rename AddSubdiagnostic trait to AddToDiagnosticJhonny Bill Mena-3/+3
2022-09-21UPDATE - rename DiagnosticHandler trait to IntoDiagnosticJhonny Bill Mena-11/+11
2022-09-21UPDATE - move SessionDiagnostic from rustc_session to rustc_errorsJhonny Bill Mena-2/+2
2022-09-05UPDATE - into_diagnostic to take a Handler instead of a ParseSessJhonny Bill Mena-4/+4
Suggested by the team in this Zulip Topic https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20SessionDiagnostic.20on.20Handler Handler already has almost all the capabilities of ParseSess when it comes to diagnostic emission, in this migration we only needed to add the ability to access source_map from the emitter in order to get a Snippet and the start_point. Not sure if this is the best way to address this gap
2022-08-22refactor: migrate to kind-less `SessionDiagnostic` derivesRejyr-8/+8
2022-08-22migrate: `rustc_lint::context`Rejyr-1/+81
2022-08-22rename: `UnknownTool` to `UnknownToolInScopedLint`Rejyr-2/+2
2022-08-22migrate: `BuiltinEllipsisInclusiveRangePatterns`Rejyr-0/+10
2022-08-22migrate: `OverruledAttribute`Rejyr-0/+40
2022-08-22hotfix: add missing importRejyr-1/+1
2022-08-22change: diagnostic `String` field to `Symbol`Rejyr-1/+1
2022-08-22migrate: `bad_attr` to `SessionDiagnostic`Rejyr-1/+20
2022-08-22migrate: `UnknownTool` error to `SessionDiagnostic`Rejyr-0/+13