about summary refs log tree commit diff
path: root/compiler/rustc_passes/src/errors.rs
AgeCommit message (Collapse)AuthorLines
2024-08-18Check that `#[may_dangle]` is properly appliedGoldstein-0/+7
It's only valid when applied to a type or lifetime parameter in `Drop` trait implementation.
2024-08-17Emit an error for invalid use of the linkage attributeShina-0/+9
2024-08-03Assert that all attributes are actually checked via `CheckAttrVisitor` and ↵Oli Scherer-0/+7
aren't accidentally usable on completely unrelated HIR nodes Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
2024-07-31Emit an error if `#[optimize]` is applied to an incompatible itemclubby789-0/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-7/+6
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-27switch to an allowlist approachFolkert-2/+3
- merge error codes - use attribute name that is incompatible in error message - add test for conditional incompatible attribute - add `linkage` to the allowlist
2024-07-16improve error message when `#[naked]` is used with `#[track-caller] and ↵Folkert-1/+1
`#[target-feature]``
2024-07-16improve error message when `#[naked]` is used with `#[inline]`Folkert-14/+10
2024-07-10Report usage of lib features in ast validationMichael Goulet-8/+0
2024-06-29Rollup merge of #127118 - surechen:fix_126789, r=jieyouxuMatthias Krüger-0/+3
Show `used attribute`'s kind for user when find it isn't applied to a `static` variable. For example : ```rust extern "C" { #[used] //~ ERROR attribute must be applied to a `static` variable static FOO: i32; // show the kind of this item to help user understand why the error is reported. } ``` fixes #126789
2024-06-29Show `used attribute`'s kind for user when find it isn't applied to a ↵surechen-0/+3
`static` variable. fixes #126789
2024-06-24coverage: Always error on `#[coverage(..)]` in unexpected placesZalathar-14/+2
This upgrades some warnings to errors, and also catches cases where the attribute was silently ignored.
2024-06-23Add hard error and migration lint for unsafe attrscarbotaniuman-10/+1
2024-06-19Rollup merge of #124580 - gurry:124556-suggest-remove-tuple-field, r=jackh726León Orell Valerian Liehr-6/+13
Suggest removing unused tuple fields if they are the last fields Fixes #124556 We now check if dead/unused fields are the last fields of the tuple and suggest their removal instead of suggesting them to be changed to `()`.
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-7/+7
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-06Error on unsafe on non-unsafe attributecarbotaniuman-1/+10
2024-05-23Rollup merge of #123623 - surechen:fix_123261, r=estebankMatthias Krüger-2/+2
Fix OutsideLoop's error suggestion: adding label `'block` for `if` block. For OutsideLoop we should not suggest add `'block` label in `if` block, or we wiil get another err: block label not supported here. fixes #123261
2024-05-22For OutsideLoop we should not suggest add 'block label in if block, or we ↵surechen-2/+2
wiil get another err: block label not supported here. fixes #123261
2024-05-21Move `#[do_not_recommend]` to the `#[diagnostic]` namespaceGeorg Semmler-5/+2
This commit moves the `#[do_not_recommend]` attribute to the `#[diagnostic]` namespace. It still requires `#![feature(do_not_recommend)]` to work.
2024-05-13Suggest removing unused tuple fields if they are the last fieldsGurinder Singh-6/+13
2024-05-08Fix Error Messages for `break` Inside CoroutinesVeera-4/+6
Previously, `break` inside `gen` blocks and functions were incorrectly identified to be enclosed by a closure. This PR fixes it by displaying an appropriate error message for async blocks, async closures, async functions, gen blocks, gen closures, gen functions, async gen blocks, async gen closures and async gen functions. Note: gen closure and async gen closure are not supported by the compiler yet but I have added an error message here assuming that they might be implemented in the future. Also, fixes grammar in a few places by replacing `inside of a $coroutine` with `inside a $coroutine`.
2024-05-04Various improvements to entrypoint codeNilstrieb-16/+0
This moves some code around and adds some documentation comments to make it easier to understand what's going on with the entrypoint logic, which is a bit complicated. The only change in behavior is consolidating the error messages for unix_sigpipe to make the code slightly simpler.
2024-05-02Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...`Martin Nordholts-7/+0
In the stabilization attempt of `#[unix_sigpipe = "sig_dfl"]`, a concern was raised related to using a language attribute for the feature: Long term, we want `fn lang_start()` to be definable by any crate, not just libstd. Having a special language attribute in that case becomes awkward. So as a first step towards towards the next stabilization attempt, this PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag `-Zon-broken-pipe=...` to remove that concern, since now the language is not "contaminated" by this feature. Another point was also raised, namely that the ui should not leak **how** it does things, but rather what the **end effect** is. The new flag uses the proposed naming. This is of course something that can be iterated on further before stabilization.
2024-04-23Rollup merge of #124218 - Xiretza:subsubdiagnostics, r=davidtwcoLeón Orell Valerian Liehr-1/+1
Allow nesting subdiagnostics in #[derive(Subdiagnostic)]
2024-04-21Pass translation closure to add_to_diag_with() as referenceXiretza-1/+1
2024-04-17weak lang items are not allowed to be #[track_caller]Ralf Jung-0/+10
2024-03-11Rename `AddToDiagnostic` as `Subdiagnostic`.Nicholas Nethercote-4/+4
To match `derive(Subdiagnostic)`. Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-11Rename `IntoDiagnostic` as `Diagnostic`.Nicholas Nethercote-12/+12
To match `derive(Diagnostic)`. Also rename `into_diagnostic` as `into_diag`.
2024-03-05Rename `SubdiagnosticMessageOp` as `SubdiagMessageOp`.Nicholas Nethercote-2/+2
2024-02-28Rename `DiagnosticSymbolList` as `DiagSymbolList`.Nicholas Nethercote-5/+5
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-13/+12
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-4/+7
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-08Rollup merge of #120734 - nnethercote:SubdiagnosticMessageOp, r=compiler-errorsMatthias Krüger-1/+2
Add `SubdiagnosticMessageOp` as a trait alias. It avoids a lot of repetition. r? matthewjasper
2024-02-08Add `SubdiagnosticMessageOp` as a trait alias.Nicholas Nethercote-1/+2
It avoids a lot of repetition.
2024-02-07Rollup merge of #120470 - estebank:issue-54196, r=compiler-errorsGuillaume Boisseau-2/+2
Mark "unused binding" suggestion as maybe incorrect Ignoring unused bindings should be a determination made by a human, `rustfix` shouldn't auto-apply the suggested change. Fix #54196.
2024-02-06Mark "unused binding" suggestion as maybe incorrectEsteban Küber-2/+2
Ignoring unused bindings should be a determination made by a human, `rustfix` shouldn't auto-apply the suggested change. Fix #54196.
2024-01-30Remove `ffi_returns_twice` featureclubby789-7/+0
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-47/+47
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-10Stop mentioning internal lang items in no_std binary errorsNilstrieb-0/+6
When writing a no_std binary, you'll be greeted with nonsensical errors mentioning lang items like eh_personality and start. That's pretty bad because it makes you think that you need to define them somewhere! But oh no, now you're getting the `internal_features` lint telling you that you shouldn't use them! But you need a no_std binary! What now? No problem! Writing a no_std binary is super easy. Just use panic=abort and supply your own platform specific entrypoint symbol (like `main`) and you're good to go. Would be nice if the compiler told you that, right? This makes it so that it does do that.
2024-01-08Remove `DiagnosticBuilder::delay_as_bug_without_consuming`.Nicholas Nethercote-1/+1
The existing uses are replaced in one of three ways. - In a function that also has calls to `emit`, just rearrange the code so that exactly one of `delay_as_bug` or `emit` is called on every path. - In a function returning a `DiagnosticBuilder`, use `downgrade_to_delayed_bug`. That's good enough because it will get emitted later anyway. - In `unclosed_delim_err`, one set of errors is being replaced with another set, so just cancel the original errors.
2024-01-08Make `DiagnosticBuilder::emit` consuming.Nicholas Nethercote-1/+1
This works for most of its call sites. This is nice, because `emit` very much makes sense as a consuming operation -- indeed, `DiagnosticBuilderState` exists to ensure no diagnostic is emitted twice, but it uses runtime checks. For the small number of call sites where a consuming emit doesn't work, the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will be removed in subsequent commits.) Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes consuming, while `delay_as_bug_without_consuming` is added (which will also be removed in subsequent commits.) All this requires significant changes to `DiagnosticBuilder`'s chaining methods. Currently `DiagnosticBuilder` method chaining uses a non-consuming `&mut self -> &mut Self` style, which allows chaining to be used when the chain ends in `emit()`, like so: ``` struct_err(msg).span(span).emit(); ``` But it doesn't work when producing a `DiagnosticBuilder` value, requiring this: ``` let mut err = self.struct_err(msg); err.span(span); err ``` This style of chaining won't work with consuming `emit` though. For that, we need to use to a `self -> Self` style. That also would allow `DiagnosticBuilder` production to be chained, e.g.: ``` self.struct_err(msg).span(span) ``` However, removing the `&mut self -> &mut Self` style would require that individual modifications of a `DiagnosticBuilder` go from this: ``` err.span(span); ``` to this: ``` err = err.span(span); ``` There are *many* such places. I have a high tolerance for tedious refactorings, but even I gave up after a long time trying to convert them all. Instead, this commit has it both ways: the existing `&mut self -> Self` chaining methods are kept, and new `self -> Self` chaining methods are added, all of which have a `_mv` suffix (short for "move"). Changes to the existing `forward!` macro lets this happen with very little additional boilerplate code. I chose to add the suffix to the new chaining methods rather than the existing ones, because the number of changes required is much smaller that way. This doubled chainging is a bit clumsy, but I think it is worthwhile because it allows a *lot* of good things to subsequently happen. In this commit, there are many `mut` qualifiers removed in places where diagnostics are emitted without being modified. In subsequent commits: - chaining can be used more, making the code more concise; - more use of chaining also permits the removal of redundant diagnostic APIs like `struct_err_with_code`, which can be replaced easily with `struct_err` + `code_mv`; - `emit_without_diagnostic` can be removed, which simplifies a lot of machinery, removing the need for `DiagnosticBuilderState`.
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-19/+19
`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-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-46/+28
And make all hand-written `IntoDiagnostic` impls generic, by using `DiagnosticBuilder::new(dcx, level, ...)` instead of e.g. `dcx.struct_err(...)`. This means the `create_*` functions are the source of the error level. This change will let us remove `struct_diagnostic`. Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`, it's necessary to pass diagnostics tests now that it's used in `into_diagnostic` functions.
2023-12-18Rename many `DiagCtxt` arguments.Nicholas Nethercote-10/+10
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-5/+5
2023-11-28Yeet E0744Michael Goulet-9/+0
2023-11-04Remove support for compiler plugins.Nicholas Nethercote-4/+0
They've been deprecated for four years. This commit includes the following changes. - It eliminates the `rustc_plugin_impl` crate. - It changes the language used for lints in `compiler/rustc_driver_impl/src/lib.rs` and `compiler/rustc_lint/src/context.rs`. External lints are now called "loaded" lints, rather than "plugins" to avoid confusion with the old plugins. This only has a tiny effect on the output of `-W help`. - E0457 and E0498 are no longer used. - E0463 is narrowed, now only relating to unfound crates, not plugins. - The `plugin` feature was moved from "active" to "removed". - It removes the entire plugins chapter from the unstable book. - It removes quite a few tests, mostly all of those in `tests/ui-fulldeps/plugin/`. Closes #29597.
2023-10-31Auto merge of #117377 - dtolnay:deprecatedsince, r=cjgillotbors-10/+0
Store #[deprecated] attribute's `since` value in parsed form This PR implements the first followup bullet listed in https://github.com/rust-lang/rust/pull/117148#issue-1960240108. We centralize error handling to the attribute parsing code in `compiler/rustc_attr/src/builtin.rs`, and thereby remove some awkward error codepaths from later phases of compilation that had to make sense of these #\[deprecated\] attributes, namely `compiler/rustc_passes/src/stability.rs` and `compiler/rustc_middle/src/middle/stability.rs`.
2023-10-30Fix #117284, Fix unused variables lint issue for args in macroyukang-6/+15
2023-10-29Delete unused InvalidDeprecationVersion diagnosticDavid Tolnay-10/+0