-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit error when user writes incorrect format for display
attribute
#160
Conversation
@magurotuna thanks! Would you be so kind to adjust Clippy? |
@tyranron Sure, done it :) |
Oh I didn't realize that MSRV is 1.36.0. I'll address it. |
@tyranron
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@magurotuna thanks! 🍻
@tyranron thanks for merging! |
cc @JelteF |
I'll try to do release somewhere this weekend
…On Tue, 11 May 2021, 17:08 Kai Ren, ***@***.***> wrote:
cc @JelteF <https://github.com/JelteF>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#160 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAI3YJT3XWUZBCJZPNRZOFLTNFB6RANCNFSM44IKRZSQ>
.
|
In case you didn't notice I created a release last weekend: v0.99.14 |
We are using `Display` macro from `derive_more` crate to easily implement `std::fmt::Display` trait for each lint's message and hint. This macro was a bit tricky; even if passed arguments are invalid format, it _does_ compile, which results in getting unexpected diagnostic outputs. This is why the issue denoland#666 happened. However, in `derive_more` v0.99.14, the macro has been refined so it now rejects arguments in invalid format at compile-time. This is so useful for us not to make a mistake. Ref: JelteF/derive_more#160
Awesome! Thanks so much ❤️ |
We are using `Display` macro from `derive_more` crate to easily implement `std::fmt::Display` trait for each lint's message and hint. This macro was a bit tricky; even if passed arguments are invalid format, it _does_ compile, which results in getting unexpected diagnostic outputs. This is why the issue #666 happened. However, in `derive_more` v0.99.14, the macro has been refined so it now rejects arguments in invalid format at compile-time. This is so useful for us not to make a mistake. Ref: JelteF/derive_more#160
What's done in this PR
Resolves #127
The compiler emit an error when a user writes incorrect format for
display
attribute, for example:for the above examples, errors that the compiler emits look like:
Motivation
I use
Display
macro and I'm really happy with it. But the other day I mistakenly wrote a code like:I had expected it to be displayed as
"Hello Bar!"
and unfortunately the code review passed and it landed.As you know, actually
Foo::Bar.to_string()
was evaluated as"Bar"
, not"Hello Bar!"
, sincefmt =
is missing.This made me think that it would be very helpful for the compiler to emit errors for invalid format at compile-time.
I'm aware that
#[display]
is a valid format, but if users write parens afterdisplay
like#[display()]
, then it most likely implies that they intend to passfmt = "..."
argument but just forget to.Hope this patch will get landed :)