-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Rename print!()/println!() to printf!()/printlnf!() #7779
Conversation
I'd actually vote for removing |
@alexcrichton: The benefit of keeping
If we didn't support the one-arg case then I'd agree with you. |
Isn't it usually |
The new names make it obvious that these generate formatted output. Add a one-argument case that uses %? to format, just like the other format-using macros (e.g. info!()).
In fact, I think the common case will be the one that adds a newline, so really it should have the shorter name. I suggest |
@metajack: We had a nice long discussion in IRC about this already. Some people feel that if we have |
A few minutes ago I pushed @pcwalton's suggested change, if anyone wants to r+ this. |
@kballard I really don't think you can stop people from using some formatted print function to print by default. It's going to be the most general and convenient way to print stuff, and so people will always reach for it first. I assume the worry is that people pass arbitrary strings as the format string. Can't the macro-ness of it also make it safe? Outlawing anything but string literals would seem the easiest way. People can always fall back to fmt! and println if they want to generate format strings programmatically and then pass them. |
@metajack: You cannot pass user input as the format string. This uses |
@kballard if safety is not a concern, why would we care if users reached for |
@metajack: This has to do with how you handle the single-argument case. If everyone used In general, it's more useful to interpret the single-arg case as allowing any type of arg (both non-strings and non-literals), and printing it using the |
Maybe we're going about this all wrong. Probably what we want is not formatted printing but var args println that converts all its arguments and separates them with spaces. This is what Sometimes format strings are useful, but the normal case of printing out various things for debugging is not one of them. So instead of
we should just have:
This would also work for:
If you need something fancier, you use fmt!, but i suspect it would get used like:
|
@metajack: Well, the goal of the macro is to replace the exceedingly common pattern |
Pull requests are not the place to discuss design. Let's bring this up on the mailing list instead. Honestly I'm not even sure these macros are warranted in the first place. |
@bstrie You're right. I started a thread on the list. |
The new names make it obvious that these generate formatted output. Add a one-argument case that uses %? to format, just like the other format-using macros (e.g. info!()).
Also I apologize for being snippy, was a bit tired yesterday. :) |
make test module detection more strict I started with some small improvements to clippy_utils/src/lib.rs, but then found that our "test" module detection would also catch words containing "test" like e.g. "attestation". So I made this a bit more strict (splitting by `'_'` and checking for `test` or `tests`), adding a test case as I went. --- *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: none
The new names make it obvious that these generate formatted output.
Add a one-argument case that uses %? to format, just like the other
format-using macros (e.g. info!()).