-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Extend useless_format
to lint values other than &str
and String
#3753
Comments
|
@RalfJung mentioned that they really dislike even changing |
Addendum: I dislike this in some cases. I think this is context-dependent. I use But when the intention is not to format user-visible text, but to e.g. turn an integer into a string, I will use |
useless_format
to lint values that implement ToStringuseless_format
to lint values other than &str
and String
Good point about So would this change be accepted? If not, should we do anything about the existing lint? |
So, format!("foo") is worse at communicating intention than "foo".to_owned() |
That depends heavily on the context. In Miri, we have some error types taking MachineError(format!("Unable to access {}", foobar)) but sometimes the message is just a string with no format variable, and then we write MachineError(format!("Division by 0")) I think this communicates intent much clearer than if we changed some of the error messages to use |
I think you're confusing consistency and/or the principle of least surprise with communicating intent there. And I happen to value the latter more than stylistic consistency. |
Well, feel free to turn on that lint in your files then, but please don't make add it to a default lint. And no, I don't think I am confusing this. The intent here is to create a string for consumption by the user -- the intent is to do formatting for UI output. The fact that the string being printed is a literal should not mean that I suddenly use entirely different syntax. The fact that the string must be owned to be put into a |
But you're not formatting that literal at all in the case we're talking about. You would use an |
Duplicate of #3156 |
format!("{}", x)
can be replaced byx.to_string()
whenx
implementsToString
. The new code is neater and probably faster.The text was updated successfully, but these errors were encountered: