about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/messages.ftl
diff options
context:
space:
mode:
authorGeorg Semmler <github@weiznich.de>2024-03-12 20:12:03 +0100
committerGeorg Semmler <github@weiznich.de>2024-03-21 08:27:26 +0100
commit5568c569c03c8c22ce81185b9e49efcaa6866050 (patch)
treef6ad4d9ea9aacd3dadd586368abc2b8fbce4afc2 /compiler/rustc_trait_selection/messages.ftl
parent7de1a1f6db26cf7af43cca74819118428e6317ee (diff)
downloadrust-5568c569c03c8c22ce81185b9e49efcaa6866050.tar.gz
rust-5568c569c03c8c22ce81185b9e49efcaa6866050.zip
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
Diffstat (limited to 'compiler/rustc_trait_selection/messages.ftl')
-rw-r--r--compiler/rustc_trait_selection/messages.ftl9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/messages.ftl b/compiler/rustc_trait_selection/messages.ftl
index 0dcba0e05f7..f96bd985237 100644
--- a/compiler/rustc_trait_selection/messages.ftl
+++ b/compiler/rustc_trait_selection/messages.ftl
@@ -19,6 +19,9 @@ trait_selection_closure_kind_mismatch = expected a closure that implements the `
 
 trait_selection_closure_kind_requirement = the requirement to implement `{$trait_prefix}{$expected}` derives from here
 
+trait_selection_disallowed_positional_argument = positional format arguments are not allowed here
+    .help = only named format arguments with the name of one of the generic types are allowed in this context
+
 trait_selection_dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entries}
 
 trait_selection_empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]`
@@ -30,6 +33,9 @@ trait_selection_ignored_diagnostic_option = `{$option_name}` is ignored due to p
 
 trait_selection_inherent_projection_normalization_overflow = overflow evaluating associated type `{$ty}`
 
+trait_selection_invalid_format_specifier = invalid format specifier
+    .help = no format specifier are supported in this position
+
 trait_selection_invalid_on_clause_in_rustc_on_unimplemented = invalid `on`-clause in `#[rustc_on_unimplemented]`
     .label = invalid on-clause here
 
@@ -60,3 +66,6 @@ trait_selection_unable_to_construct_constant_value = unable to construct a const
 
 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
+
+trait_selection_wrapped_parser_error = {$description}
+    .label = {$label}