-
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
Improve suggestion for missing fmt str in println #52394
Conversation
Improve suggestion for missing fmt str in println Avoid using `concat!(fmt, "\n")` to improve the diagnostics being emitted when the first `println!()` argument isn't a formatting string literal. Fix #52347.
cc @ollie27 |
This comment has been minimized.
This comment has been minimized.
☀️ Test successful - status-travis |
@rust-timer build effb34d |
Insufficient permissions to issue commands to rust-timer. |
cc @kennytm |
Note to self: Need to fix |
@rust-timer build effb34d |
Success: Queued effb34d with parent 49f1e5d, comparison URL. |
src/libstd/macros.rs
Outdated
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); | ||
($fmt:expr) => ({ | ||
print!($fmt); | ||
print!("\n"); |
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.
Using two print!
s will mean stdout will be unlocked before printing the \n
. Replacing these two rules with
($($arg:tt)*) => (print!("{}\n", format_args!($($arg)*)));
will avoid that issue.
src/libsyntax_ext/concat.rs
Outdated
} | ||
} | ||
} | ||
if missing_literal.len() > 0 { | ||
let mut err = cx.struct_span_err(missing_literal, "expected a literal"); | ||
err.note("only `&str` literals can be passed to `concat!()`"); |
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.
Most literals can be passed to concat!
, not just &str
.
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.
True, but the wording "only literals..." could be harder to understand to newcomers... What do you think of
only literals (like `"foo"`, `42` and `3.14`) can be passed to `concat!()`
@kennytm can we get another perf run? After the last change I doubt this will introduce any regression. |
@bors try |
Improve suggestion for missing fmt str in println Avoid using `concat!(fmt, "\n")` to improve the diagnostics being emitted when the first `println!()` argument isn't a formatting string literal. Fix #52347.
This comment has been minimized.
This comment has been minimized.
☀️ Test successful - status-travis |
@rust-timer build ac3b07a |
Success: Queued ac3b07a with parent fb8bde0, comparison URL. |
Perf is ready. Looks even worse than the previous one. |
In that case I guess I'll have to come up with something more involved if we want this :-/ |
Cc @dtolnay after the talk in Rust Meetup. Note to self, see if marching quote literals is possible. |
Address rust-lang#30143 as well. `writeln!()` hasn't been changed.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I'm not entirely sure why (or if) this is needed.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@bors r=oli-obk |
📌 Commit dc563d9 has been approved by |
Improve suggestion for missing fmt str in println Avoid using `concat!(fmt, "\n")` to improve the diagnostics being emitted when the first `println!()` argument isn't a formatting string literal. Fix #52347.
☀️ Test successful - status-appveyor, status-travis |
📣 Toolstate changed by #52394! Tested on commit 3d51086. 💔 clippy-driver on windows: test-pass → test-fail (cc @Manishearth @llogiq @mcarton @oli-obk, @rust-lang/infra). |
Tested on commit rust-lang/rust@3d51086. Direct link to PR: <rust-lang/rust#52394> 💔 clippy-driver on windows: test-pass → test-fail (cc @Manishearth @llogiq @mcarton @oli-obk, @rust-lang/infra). 💔 clippy-driver on linux: test-pass → test-fail (cc @Manishearth @llogiq @mcarton @oli-obk, @rust-lang/infra).
|
Avoid using
concat!(fmt, "\n")
to improve the diagnostics beingemitted when the first
println!()
argument isn't a formatting stringliteral.
Fix #52347.