-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
format_push_string could use some more information #9077
Comments
I am curious why this change landed on Rust stable and has preference over the |
@Jasperav seems like a choice of performance over style:
I'm not necessarily opposed to the idea (not sure how I feel about it yet since I haven't run into it much), but if my_string.push_fmt("{} world", "hello");
my_string.push_format("{} world", "hello");
// or format_push / fmt_push etc.
write_string!(my_string, "{} world", "hello"); Would all be nice (although the method seems more convenient) |
@rustbot claim |
I'm not a huge fan of this lint. Also, I haven't checked but I'd be curious if the extra allocation by |
Recommending to switch clear infallible code to code that ignores errors certainly seems like a step backwards to me, even if it is faster. If people get into the habit of ignoring errors, it will eventually bite them, likely in a hard to debug way. Surely |
Fixes the CI build. The suggested changes turn infallible code into one that ignores errors, not good! I'll just ignore this lint for now. See also rust-lang/rust-clippy#9077 (comment)
As I understand it, this is the source for the the Write impl used by String: https://doc.rust-lang.org/src/std/io/impls.rs.html#380-412. No |
I don't think it matters if |
@Victor-N-Suadicani that's what I meant here: #9077 (comment), I agree that it would make more sense (and have less of a "surprise" element) as a separate macro that doesn't return an |
Description
clippy::format_push_string
currently outputs the following:(the following is part of a fork of
human_panic
)I think this description could use a bit more information regarding the difference between
format!
andwrite!
, aswrite!
returns aResult
, which the linked example instructs you to ignore:The issue with this is that if you're not familiar with
write!
, you don't know which errors you're ignoring by making this change, and if you use-D clippy::all
(as e.g. we do in my project) you have to either make this change or use#[allow(clippy::format_push_string)]
for your code to compile. This isn't ideal as you may end up making a decision without all the needed information.If you look into
write!
, you'll find that thewrite_xyz
methods have the following description:Which doesn't really give you any more information. (edit: apparently this is meant to reflect any implementation rather than the default implementation, which is why it's a bit vague)
write_fmt
, used bywrite!
(on$dst
which may mean it's using something other than the linked documentation as I'm not familiar with what$dst
is in this context), doesn't have an# Errors
section.If you continue going down the rabbit hole,
write_fmt
callswrite
, which also does not have an# Errors
section. It itself callswrite_str
, and has anunsafe
block that returns aResult
as well.My point isn't to complain or criticize, but rather to point out that if you're not familiar with the intricacies of
write!
the lint info currently doesn't give you a good idea of what potential errors you're ignoring by making this switch if using it as directed. Even if you do add handling code and change the function you usedformat!
in to return aResult
, the result (no pun intended) is that you now have a new failure scenario you don't know enough about.My assumption is that
format!
callswrite!
somewhere and ignores the error and that's the reason why they were deemed equivalent, but I'd add that to the description if that's the case.Thanks!
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: