-
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
format_args: allow omission of format string #12384
Conversation
A default format string of Poly {:?} is generated to match the number of passed arguments. This propagates to all fmt macros, such as println!, debug!, format!, write!, etc. Example: println!("{:?}", value); => println!(value); fixes rust-lang#12015
What is the benefit of this, especially if it emits a note every time it's used? If I see |
benefit is in #12015 You might expect Other usage: JavaScript: |
Why allow it at all, if it's going to unconditionally issue a note? |
I don't understand what else you may be asking that isn't answered in previous comments and is in #12015. |
#12015 makes no mention of the |
ast::LitStr(ref s, _) => return Some(s.get().to_owned()), | ||
_ => cx.span_note(l.span, note_msg) | ||
}, | ||
_ => cx.span_note(expr.span, note_msg) |
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.
... and this one.
Sadly, the inability of |
@huonw yea, I know the notes are there. I wrote them. Is the answer in #12384 (comment) not sufficient? I may have the wrong understanding of span_note, as well. |
@seanmonstar no, it doesn't address the compilation noise it generates, e.g. fn foo(x: int) {
println!(x); // note: format string literal missing, using default
bar(x + 1);
}
fn bar(x: int) {
println!(x); // note: format string literal missing, using default
baz(x + 2);
}
fn baz(x: int) {
println!(x); // note: format string literal missing, using default
// ...
}
fn main() { foo(0) } Everything single one of those println!(some_variable); // ok, omitted format string on purpose
println!(&mut writer, "a {} b", 1); // oops, was meant to be `writeln!` In any case, I think this shouldn't be done via |
I personally think that |
I actually disagree on each point. Coming from other languages like Java or JavaScript, something like println is sometimes use to output information to a user, such as for command line scripts, but almost seems more likely to just be quick debug lines. I pointed at past work with Using another macro to do the same thing, but to have a different name, seems less elegant. Java has seared into my mind that As for the note at each usage, that seems quite fine to me. The extra noise can help you to remember to remove it after it's no longer needed. Plus, I'd expect an ability to eventually ignore note level messages from the compiler, such as However, being the newcomer, I'll concede to not knowing what's best for Rust. Cheers. |
That sounds like a terrible idea. If I'm seeing a note, it's because I'm doing something wrong. I should not be allowed to squelch those messages. Ignored warnings is a terrible problem in C/C++, and I do not want the same to happen to Rust. |
Again, I must have misunderstood the severity of "note". "note" sounds potentially ignorable to me (it also outputs in green in terminal, which conveys "all good here, boss".) |
Silencing all notes hides legitimate misuse of |
@huonw |
Any compiler output, beyond telling me that it's compiling a file, is a cause for concern. The compiler is not in the habit of printing messages along the lines of "good job, buddy!" Anything it says is because it thinks there's a problem. To that end, I do not want the ability to hide anything the compiler outputs. And given that, I do not want any API that will emit a note as a matter of normal usage. Emitting a note due to a debugging function is ok, as it's a reminder that you're using a debugging function, but in that case I would expect to be using a different name altogether, such as |
Ah, ok (I've not used Node). However, Node inherits its semantics of |
Ok, I'll close this and try again with |
…eykril Generate variant: insert code in file with enum definition Closes rust-lang#12372
A default format string of Poly {:?} is generated to match the number
of passed arguments. This propagates to all fmt macros, such as println!,
debug!, format!, write!, etc.
Example: println!("{:?}", value); => println!(value);
fixes #12015