Commit Graph

27 Commits

Author SHA1 Message Date
Karol Zwolak
d14b83e378 bless tests with new lint messages 2025-08-19 21:27:10 +02:00
mejrs
a7bf5c4fa2 Split up the unknown_or_malformed_diagnostic_attributes lint 2025-07-11 01:24:24 +02:00
mejrs
03c846ee1d Introduce ParseMode::diagnostic and fix multiline spans 2025-06-09 16:28:58 +02:00
mejrs
f002abad5e change FormatString::parse to only return the first error 2025-06-09 16:28:58 +02:00
mejrs
9ffd0bf75a do away with _Self and TraitName and check generic params for rustc_on_unimplemented 2025-05-17 15:15:53 +02:00
bors
7188f45311 Auto merge of #140503 - matthiaskrgr:rollup-n7zigts, r=matthiaskrgr
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-30 12:09:10 +00:00
Vadim Petrochenkov
20faf8532b compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
mejrs
478b3789ce Move on impl position test to proper directory 2025-04-29 12:19:29 +02:00
mejrs
2007c8994d Write the format string parserand split it from conditions parser 2025-04-10 17:28:23 +02:00
Vadim Petrochenkov
b3f75353a2 UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
Eric Huss
1b0e78738b Add reference annotations for diagnostic attributes
This adds reference annotations for `diagnostic::on_unimplmented` and
the `diagnostic` namespace in general.
2024-11-18 10:45:26 -08:00
Eric Huss
5319425128 Move diagnostic::on_unimplemented test to the directory with all the other tests 2024-11-15 14:09:37 -08:00
Lieselotte
dda3066805 Remove 'apostrophes' from rustc_parse_format 2024-10-14 23:22:51 +02:00
Georg Semmler
5568c569c0 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
2024-03-21 08:27:26 +01:00
Georg Semmler
d013b5a462 Stabilize the #[diagnostic] namespace and #[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
2024-02-27 08:50:56 +01:00
许杰友 Jieyou Xu (Joe)
ec2cc761bc [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
George-lewis
d56cdd48cb Bless tests
Update tests
2024-01-13 12:46:58 -05:00
Georg Semmler
91e1af3862 Add a test that emitting diagnostics does not require the crate to use
the corresponding feature.
2024-01-05 15:23:10 +01:00
Georg Semmler
1a1cd6e6db Restrict what symbols can be used in #[diagnostic::on_unimplemented] format strings
This commit restricts what symbols can be used in a format string for
any option of the `diagnostic::on_unimplemented` attribute. We
previously allowed all the ad-hoc options supported by the internal
`#[rustc_on_unimplemented]` attribute. For the stable attribute we only
want to support generic parameter names and `{Self}` as parameters.  For
any other parameter an warning is emitted and the parameter is replaced
by the literal parameter string, so for example `{integer}` turns into
`{integer}`. This follows the general design of attributes in the
`#[diagnostic]` attribute namespace, that any syntax "error" is treated
as warning and subsequently ignored.
2023-12-04 10:00:33 +01:00
Nilstrieb
41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Georg Semmler
10538d4d2b Add some additional warnings for duplicated diagnostic items
This commit adds warnings if a user supplies several diagnostic options
where we can only apply one of them. We explicitly warn about ignored
options here. In addition a small test for these warnings is added.
2023-11-17 07:28:43 +01:00
Georg Semmler
160b1793b2 Allows #[diagnostic::on_unimplemented] attributes to have multiple
notes

This commit extends the `#[diagnostic::on_unimplemented]` (and
`#[rustc_on_unimplemented]`) attributes to allow multiple `note`
options. This enables emitting multiple notes for custom error messages.
For now I've opted to not change any of the existing usages of
`#[rustc_on_unimplemented]` and just updated the relevant compile tests.
2023-10-27 12:42:42 +02:00
Georg Semmler
3d03a8a653 Fix a span for one of the test cases 2023-10-20 13:24:58 +02:00
Georg Semmler
9017b974ee Improve the warning messages for the #[diagnostic::on_unimplemented]
This commit improves warnings emitted for malformed on unimplemented
attributes by:

* Improving the span of the warnings
* Adding a label message to them
* Separating the messages for missing and unexpected options
* Adding a help message that says which options are supported
2023-10-19 15:00:47 +02:00
Georg Semmler
232aaeba7c Handle several #[diagnostic::on_unimplemented] attributes correctly
This PR fixes an issues where rustc would ignore subsequent
`#[diagnostic::on_unimplemented]` attributes. The [corresponding
RFC](https://rust-lang.github.io/rfcs/3368-diagnostic-attribute-namespace.html)
specifies that the first matching instance of each option is used.
Invalid attributes are linted and otherwise ignored.
2023-10-11 22:01:59 +02:00
Alex Macleod
5453a9f34d Add a note to duplicate diagnostics 2023-10-05 01:04:41 +00:00
Georg Semmler
5b8a7a0917 #[diagnostic::on_unimplemented] without filters
This commit adds support for a `#[diagnostic::on_unimplemented]`
attribute with the following options:

* `message` to customize the primary error message
* `note` to add a customized note message to an error message
* `label` to customize the label part of the error message

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
Co-authored-by: Michael Goulet <michael@errs.io>
2023-09-12 20:03:18 +02:00