-
Notifications
You must be signed in to change notification settings - Fork 13k
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
print! and println! (and other similar macro pairs) accept differing types of "format strings" #47441
Comments
Personally, I don't think that One "solution" would be to wrap a dummy |
The same applies for |
Duplicate of #30143. There's not really anything we can do here without breaking back compat. |
Why not change |
The writeln/etc behavior is a bug, not a feature. |
I mean... "bugs" get fixed. This has been declared unfixable, so it's now a "feature". Unless somehow epochs will allow us to undo that mistake, isn't it better to be consistently broken? |
I do not agree that making a misfeature larger for "consistency" is a good idea. |
|
I have a reason: it is really annoying to accidentally leave off format arguments and have the result compile and print your template string. |
I'm not understanding your example:
|
Oops, I thought I remembered that doing weird things but must have been thinking of something else. Regardless, though, this is a duplicate of that issue. As far as I know, no one actually intentionally uses this behavior. I don't know why we would go out of our way to extend the support of a weird oddity. |
As a more real argument as to why this behavior is bad, it seems better to know that the formatting functions expect a string literal first always, as opposed to a string literal first, unless you want to print a literal value, in which case you can just put it in. If we did anything like this IMO, we'd want |
So I feel like overall consensus though is that this is a duplicate issue and we don't want to "fix" (i.e., for consistency) print! and also don't want to remove (non backwards compatibly) the |
@sfackler : I think you remembered your issue backward. If you use |
Ah yeah that might have been it. |
Closing as duplicate of #30143 |
println!
accepts non-string literals as the format string:print!
does not:This is because
println!
is implemented as callingprint!
with the result ofconcat!
:https://github.com/rust-lang/rust/blob/1.23.0/src/libstd/macros.rs#L150-L154
print!
just callsformat_args
:https://github.com/rust-lang/rust/blob/1.23.0/src/libstd/macros.rs#L119-L121
However,
concat!
stringifies its argument:https://github.com/rust-lang/rust/blob/1.23.0/src/libsyntax_ext/concat.rs#L32-L54
This means that the "format string" can be any of:
The text was updated successfully, but these errors were encountered: