Description
The following are some unexpected behaviors I see with the formatting strings in the diagnostic::on_unimplemented
attribute. I'm not sure that the on_unimplemented
attribute should actually be using std's format parsing, but if it is, the following seem like issues with the current implementation.
Broken formatting is ignored
#[diagnostic::on_unimplemented(message = "Test } thing")]
trait ImportantTrait<A> {}
Anything after the }
is ignored, and not included in the message output.
Expectation: There should be a warning that the string is malformed.
Empty or positional arguments cause an error
#[diagnostic::on_unimplemented(message = "Test {}")]
trait ImportantTrait<A> {}
or
#[diagnostic::on_unimplemented(message = "Test {1:}")]
trait ImportantTrait<A> {}
These generate an error. However, my understanding of the attribute is that it tries to only generate warnings for things it doesn't understand. I would expect this to also generate a warning.
Format options are ignored
#[diagnostic::on_unimplemented(message = "Test {Self:123}")]
trait ImportantTrait<A> {}
This does not generate a warning or error. I would expect it to generate a warning that anything after the :
is ignored. This includes width, precision, debug formatting, etc.
Invalid format options do weird things
#[diagnostic::on_unimplemented(message = "Test {Self:!}")]
trait ImportantTrait<A> {}
The error message generated with this is the type followed by a !
. I would expect this to generate a warning that the format arguments are not valid (similar to how format!
works).
Meta
rustc --version --verbose
:
rustc 1.78.0-nightly (4a0cc881d 2024-03-11)
binary: rustc
commit-hash: 4a0cc881dcc4d800f10672747f61a94377ff6662
commit-date: 2024-03-11
host: aarch64-apple-darwin
release: 1.78.0-nightly
LLVM version: 18.1.0
cc @weiznich