1
Fork 0

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.
This commit is contained in:
Georg Semmler 2023-12-01 07:26:05 +01:00
parent 74fccd0b50
commit 1a1cd6e6db
No known key found for this signature in database
GPG key ID: A87BCEE5205CE489
6 changed files with 523 additions and 61 deletions

View file

@ -55,3 +55,6 @@ trait_selection_trait_has_no_impls = this trait has no implementations, consider
trait_selection_ty_alias_overflow = in case this is a recursive type alias, consider using a struct, enum, or union instead
trait_selection_unable_to_construct_constant_value = unable to construct a constant value for the unevaluated constant {$unevaluated}
trait_selection_unknown_format_parameter_for_on_unimplemented_attr = there is no parameter `{$argument_name}` on trait `{$trait_name}`
.help = expect either a generic argument name or {"`{Self}`"} as format argument