about summary refs log tree commit diff
path: root/tests/ui/diagnostic_namespace
AgeCommit message (Collapse)AuthorLines
2025-08-19bless tests with new lint messagesKarol Zwolak-15/+15
2025-07-11Split up the `unknown_or_malformed_diagnostic_attributes` lintmejrs-28/+34
2025-06-09Introduce ParseMode::diagnostic and fix multiline spansmejrs-55/+134
2025-06-09change FormatString::parse to only return the first errormejrs-28/+12
2025-06-09Add test for flailing diagnostic spansmejrs-0/+114
2025-05-17do away with `_Self` and `TraitName` and check generic params for ↵mejrs-46/+77
rustc_on_unimplemented
2025-04-30Auto merge of #140503 - matthiaskrgr:rollup-n7zigts, r=matthiaskrgrbors-6/+7
Rollup of 11 pull requests Successful merges: - #136160 (Remove backticks from `ShouldPanic::YesWithMessage`'s `TrFailedMsg`) - #139059 (uses_power_alignment: wording tweaks) - #139192 (mention provenance in the pointer::wrapping_offset docs) - #140312 (Improve pretty-printing of braces) - #140404 (rm `TypeVistable` impls for `Canonical`) - #140437 (enable msa feature for mips in codegen tests) - #140438 (Add `rust.debug-assertions-tools` option) - #140439 (miri: algebraic intrinsics: bring back float non-determinism) - #140445 (Treat ManuallyDrop as ~const Destruct) - #140446 (chore: fix some tests) - #140448 (Rename `rustc_query_append!` to `rustc_with_all_queries!`) r? `@ghost` `@rustbot` modify labels: rollup
2025-04-30compiletest: Make diagnostic kind mandatory on line annotationsVadim Petrochenkov-6/+8
2025-04-29Move `on impl position` test to proper directorymejrs-6/+7
2025-04-24norm nested aliases before evaluating the parent goallcnr-5/+8
2025-04-19Rollup merge of #139091 - mejrs:format, r=compiler-errorsChris Denton-68/+116
Rewrite on_unimplemented format string parser. This PR rewrites the format string parser for `rustc_on_unimplemented` and `diagnostic::on_unimplemented`. I plan on moving this code (and more) into the new attribute parsing system soon and wanted to PR it separately. This PR introduces some minor differences though: - `rustc_on_unimplemented` on trait *implementations* is no longer checked/used - this is actually never used (outside of some tests) so I plan on removing it in the future. - for `rustc_on_unimplemented`, it introduces the `{This}` argument in favor of `{ThisTraitname}` (to be removed later). It'll be easier to parse. - for `rustc_on_unimplemented`, `Self` can now consistently be used as a filter, rather than just `_Self`. It used to not match correctly on for example `Self = "[{integer}]"` - Some error messages now have better spans. Fixes https://github.com/rust-lang/rust/issues/130627
2025-04-14Disable usage on trait impls and aliasesmejrs-0/+48
2025-04-10Deeply normalize obligations in BestObligationMichael Goulet-7/+8
2025-04-10Write the format string parserand split it from conditions parsermejrs-68/+68
2025-04-08UI tests: add missing diagnostic kinds where possibleVadim Petrochenkov-5/+5
2025-03-24Add do_not_recommend typo helpmejrs-1/+18
2025-02-21More sophisticated span trimmingMichael Goulet-6/+4
2025-02-18Add reference annotations for the `do_not_recommend` attributeEric Huss-50/+59
2025-02-10Show diff suggestion format on verbose replacementEsteban Küber-6/+9
``` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> $DIR/attempted-access-non-fatal.rs:7:15 | LL | let _ = 2.l; | ^ | help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix | LL - let _ = 2.l; LL + let _ = 2.0f64; | ```
2025-01-31Manually walk into WF obligations in BestObligation proof tree visitorMichael Goulet-13/+3
2024-12-18Also warn against `#[diagnostic::do_not_recommend]` on plain implsGeorg Semmler-2/+18
2024-12-18Stabilize `#[diagnostic::do_not_recommend]`Georg Semmler-227/+49
This commit seeks to stabilize the `#[diagnostic::do_not_recommend]` attribute. This attribute was first proposed as `#[do_not_recommend`] attribute in RFC 2397 (https://github.com/rust-lang/rfcs/pull/2397). It gives the crate authors the ability to not suggest to the compiler to not show certain traits in it's error messages. With the presence of the `#[diagnostic]` tool attribute namespace it was decided to move the attribute there, as that lowers the amount of guarantees the compiler needs to give about the exact way this influences error messages. It turns the attribute into a hint which can be ignored. In addition to the original proposed functionality this attribute now also hides the marked trait in help messages ("This trait is implemented by: "). The attribute does not accept any argument and can only be placed on trait implementations. If it is placed somewhere else a lint warning is emitted and the attribute is otherwise ignored. If an argument is detected a lint warning is emitted and the argument is ignored. This follows the rules outlined by the diagnostic namespace. This attribute allows crates like diesel to improve their error messages drastically. The most common example here is the following error message: ``` error[E0277]: the trait bound `&str: Expression` is not satisfied --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:53:15 | LL | SelectInt.check("bar"); | ^^^^^ the trait `Expression` is not implemented for `&str`, which is required by `&str: AsExpression<Integer>` | = help: the following other types implement trait `Expression`: Bound<T> SelectInt note: required for `&str` to implement `AsExpression<Integer>` --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:26:13 | LL | impl<T, ST> AsExpression<ST> for T | ^^^^^^^^^^^^^^^^ ^ LL | where LL | T: Expression<SqlType = ST>, | ------------------------ unsatisfied trait bound introduced here ``` By applying the new attribute to the wild card trait implementation of `AsExpression` for `T: Expression` the error message becomes: ``` error[E0277]: the trait bound `&str: AsExpression<Integer>` is not satisfied --> $DIR/as_expression.rs:55:15 | LL | SelectInt.check("bar"); | ^^^^^ the trait `AsExpression<Integer>` is not implemented for `&str` | = help: the trait `AsExpression<Text>` is implemented for `&str` = help: for that trait implementation, expected `Text`, found `Integer` ``` which makes it much easier for users to understand that they are facing a type mismatch. Other explored example usages included * This standard library error message: https://github.com/rust-lang/rust/pull/128008 * That bevy derived example: https://github.com/rust-lang/rust/blob/e1f306899514ea80abc1d1c9f6a57762afb304a3/tests/ui/diagnostic_namespace/do_not_recommend/supress_suggestions_in_help.rs (No more tuple pyramids) Fixes #51992
2024-12-18Check `#[diagnostic::do_not_recommend]` for argumentsGeorg Semmler-0/+68
This commit adds a check that verifies that no arguments are passed to `#[diagnostic::do_not_recommend]`. If we detect arguments we emit a warning.
2024-12-18Improve testing coverage for `#[diagnostic::do_not_recommend]`Georg Semmler-14/+230
This PR aims to improve the testing coverage for `#[diagnostic::do_not_recommend]`. It ensures that all tests are run for the old and new solver to verify that the behaviour is the same for both variants. It also adds two new tests: * A test with 4 traits having wild card impl for each other, with alternating `#[diagnostic::do_not_recommend]` attributse * A test with a lifetime dependend wild card impl, which is something that's not supported yet
2024-11-27Update tests to use new proc-macro headerEric Huss-5/+1
2024-11-18Add reference annotations for diagnostic attributesEric Huss-146/+167
This adds reference annotations for `diagnostic::on_unimplmented` and the `diagnostic` namespace in general.
2024-11-15Move diagnostic::on_unimplemented test to the directory with all the other testsEric Huss-0/+51
2024-11-04Rollup merge of #132583 - mejrs:tuples, r=compiler-errorsMatthias Krüger-0/+12
Suggest creating unary tuples when types don't match a trait When you want to have a variadic function, a common workaround to implement this is to create a trait and then implement that trait for various tuples. For example in `pyo3` there exists ```rust /// Calls the object with only positional arguments. pub fn call1(&self, args: impl IntoPy<Py<PyTuple>>) -> PyResult<&PyAny> { ... } ``` with various impls like ```rust impl<A: IntoPy<PyObject> IntoPy<Py<PyAny>> for (A,) impl<A: IntoPy<PyObject, B: IntoPy<PyObject> IntoPy<Py<PyAny>> for (A, B) ... etc ``` This means that if you want to call the method with a single item you have to create a unary tuple, like `(x,)`, rather than just `x`. This PR implements a suggestion to do that, if applicable.
2024-11-04Suggest creating unary tuplesmejrs-0/+12
2024-11-02Add trait diff highlighting logic and use it in E0277Esteban Küber-2/+4
When a trait is not implemented for a type, but there *is* an `impl` for another type or different trait params, we format the output to use highlighting in the same way that E0308 does for types. The logic accounts for 3 cases: - When both the type and trait in the expected predicate and the candidate are different - When only the types are different - When only the trait generic params are different For each case, we use slightly different formatting and wording.
2024-10-16Stop inverting expectation in normalization errorsMichael Goulet-4/+1
2024-10-14Remove `'apostrophes'` from `rustc_parse_format`Lieselotte-4/+4
2024-08-09Add testMichael Goulet-0/+42
Co-authored-by: Georg Semmler <github@weiznich.de>
2024-07-11Allows `#[diagnostic::do_not_recommend]` to supress trait impls in ↵Georg Semmler-0/+61
suggestions as well This commit changes the error reporting mechanism for not implemented traits to skip impl marked as `#[diagnostic::do_not_recommend]` in the help part of the error message ("the following other types implement trait `Foo`:"). The main use case here is to allow crate authors to skip non-meaningful confusing suggestions. A common example for this are fully generic impls on tuples.
2024-07-02Actually report normalization-based type errors correctly for alias-relate ↵Michael Goulet-1/+4
obligations in new solver
2024-06-12Walk into alias-eq nested goals even if normalization failsMichael Goulet-1/+1
2024-05-29Refactor `#[diagnostic::do_not_recommend]` supportGeorg Semmler-0/+57
This commit refactors the `#[do_not_recommend]` support in the old parser to also apply to projection errors and not only to selection errors. This allows the attribute to be used more widely.
2024-05-28eagerly normalize when adding goalslcnr-4/+21
2024-05-21Move `#[do_not_recommend]` to the `#[diagnostic]` namespaceGeorg Semmler-3/+148
This commit moves the `#[do_not_recommend]` attribute to the `#[diagnostic]` namespace. It still requires `#![feature(do_not_recommend)]` to work.
2024-05-19Actually use the `#[do_not_recommend]` attribute if presentGeorg Semmler-14/+150
This change tweaks the error message generation to actually use the `#[do_not_recommend]` attribute if present by just skipping the marked trait impl in favour of the parent impl. It also adds a compile test for this behaviour. Without this change the test would output the following error: ``` error[E0277]: the trait bound `&str: Expression` is not satisfied --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:53:15 | LL | SelectInt.check("bar"); | ^^^^^ the trait `Expression` is not implemented for `&str`, which is required by `&str: AsExpression<Integer>` | = help: the following other types implement trait `Expression`: Bound<T> SelectInt note: required for `&str` to implement `AsExpression<Integer>` --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:26:13 | LL | impl<T, ST> AsExpression<ST> for T | ^^^^^^^^^^^^^^^^ ^ LL | where LL | T: Expression<SqlType = ST>, | ------------------------ unsatisfied trait bound introduced here ``` Note how that mentions `&str: Expression` before and now mentions `&str: AsExpression<Integer>` instead which is much more helpful for users. Open points for further changes before stabilization: * We likely want to move the attribute to the `#[diagnostic]` namespace to relax the guarantees given? * How does it interact with the new trait solver?
2024-05-15Add `on_unimplemented" typo suggestionsmejrs-0/+58
2024-05-07Fix ICEs in diagnostic::on_unimplementedMichael Goulet-0/+134
2024-05-07Add more ICEs due to malformed diagnostic::on_unimplementedMichael Goulet-35/+56
2024-05-08Auto merge of #124683 - estebank:issue-124651, r=compiler-errorsbors-0/+36
Do not ICE on foreign malformed `diagnostic::on_unimplemented` Fix #124651.
2024-05-07Add test for #124651Esteban Küber-0/+36
2024-05-04Implement do_not_recommend in the new solverMichael Goulet-0/+58
2024-03-21Rollup merge of #122402 - weiznich:fix/122391, r=compiler-errorsMatthias Krüger-0/+238
Make `#[diagnostic::on_unimplemented]` format string parsing more robust This commit fixes several issues with the format string parsing of the `#[diagnostic::on_unimplemented]` attribute that were pointed out by `@ehuss.` In detail it fixes: * Appearing format specifiers (display, etc). For these we generate a warning that the specifier is unsupported. Otherwise we ignore them * Positional arguments. For these we generate a warning that positional arguments are unsupported in that location and replace them with the format string equivalent (so `{}` or `{n}` where n is the index of the positional argument) * Broken format strings with enclosed }. For these we generate a warning about the broken format string and set the emitted message literally to the provided unformatted string * Unknown format specifiers. For these we generate an additional warning about the unknown specifier. Otherwise we emit the literal string as message. This essentially makes those strings behave like `format!` with the minor difference that we do not generate hard errors but only warnings. After that we continue trying to do something unsuprising (mostly either ignoring the broken parts or falling back to just giving back the literal string as provided). Fix #122391 r? `@compiler-errors`
2024-03-21Make `#[diagnostic::on_unimplemented]` format string parsing more robustGeorg Semmler-0/+238
This commit fixes several issues with the format string parsing of the `#[diagnostic::on_unimplemented]` attribute that were pointed out by @ehuss. In detail it fixes: * Appearing format specifiers (display, etc). For these we generate a warning that the specifier is unsupported. Otherwise we ignore them * Positional arguments. For these we generate a warning that positional arguments are unsupported in that location and replace them with the format string equivalent (so `{}` or `{n}` where n is the index of the positional argument) * Broken format strings with enclosed }. For these we generate a warning about the broken format string and set the emitted message literally to the provided unformatted string * Unknown format specifiers. For these we generate an additional warning about the unknown specifier. Otherwise we emit the literal string as message. This essentially makes those strings behave like `format!` with the minor difference that we do not generate hard errors but only warnings. After that we continue trying to do something unsuprising (mostly either ignoring the broken parts or falling back to just giving back the literal string as provided). Fix #122391
2024-03-14Ungate the `UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES` lintGeorg Semmler-0/+21
This was missed during stablisation of the `#[diagnostic]` attribute namespace. Fixes #122446
2024-02-27Stabilize the `#[diagnostic]` namespace and ↵Georg Semmler-178/+90
`#[diagnostic::on_unimplemented]` attribute This PR stabilizes the `#[diagnostic]` attribute namespace and a minimal option of the `#[diagnostic::on_unimplemented]` attribute. The `#[diagnostic]` attribute namespace is meant to provide a home for attributes that allow users to influence error messages emitted by the compiler. The compiler is not guaranteed to use any of this hints, however it should accept any (non-)existing attribute in this namespace and potentially emit lint-warnings for unused attributes and options. This is meant to allow discarding certain attributes/options in the future to allow fundamental changes to the compiler without the need to keep then non-meaningful options working. The `#[diagnostic::on_unimplemented]` attribute is allowed to appear on a trait definition. This allows crate authors to hint the compiler to emit a specific error message if a certain trait is not implemented. For the `#[diagnostic::on_unimplemented]` attribute the following options are implemented: * `message` which provides the text for the top level error message * `label` which provides the text for the label shown inline in the broken code in the error message * `note` which provides additional notes. The `note` option can appear several times, which results in several note messages being emitted. If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value. Any other occurrence generates an lint warning. For any other non-existing option a lint-warning is generated. All three options accept a text as argument. This text is allowed to contain format parameters referring to generic argument or `Self` by name via the `{Self}` or `{NameOfGenericArgument}` syntax. For any non-existing argument a lint warning is generated. Tracking issue: #111996