-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Avoid &format("...")
calls in error message code.
#111633
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
It's unused.
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
This comment has been minimized.
This comment has been minimized.
Error message all end up passing into a function as an `impl Into<{D,Subd}iagnosticMessage>`. If an error message is creatd as `&format("...")` that means we allocate a string (in the `format!` call), then take a reference, and then clone (allocating again) the reference to produce the `{D,Subd}iagnosticMessage`, which is silly. This commit removes the leading `&` from a lot of these cases. This means the original `String` is moved into the `{D,Subd}iagnosticMessage`, avoiding the double allocations. This requires changing some function argument types from `&str` to `String` (when all arguments are `String`) or `impl Into<{D,Subd}iagnosticMessage>` (when some arguments are `String` and some are `&str`).
00e1b9c
to
01e33a3
Compare
I'm not sure this is a good idea as this error code is to be migrated away from, and some crates have migration PRs open for a while already, and this PR might cause conflicts for them. Edit: talking about the second commit. The first commit is fine. |
@davidtwco approved a bunch of similar changes in #110579. The changes are all very simple, so any conflicts should be easy to resolve. |
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.
A couple .as_str()
s that I don't really understand, but otherwise LGTM.
@bors r+ |
Rollup of 7 pull requests Successful merges: - rust-lang#110884 (Support RISC-V unaligned-scalar-mem target feature) - rust-lang#111160 (Update serde in workspace and non-synced dependencies) - rust-lang#111168 (Specialize ToString implementation for fmt::Arguments) - rust-lang#111527 (add examples of port 0 binding behavior) - rust-lang#111561 (Include better context for "already exists" error in compiletest) - rust-lang#111633 (Avoid `&format("...")` calls in error message code.) - rust-lang#111679 (Remove libs message about ACPs from triagebot) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…ffleLapkin Avoid `&format("...")` calls in error message code. Some error message cleanups. Best reviewed one commit at a time. r? `@davidtwco`
…sage-code, r=oli-obk Avoid `&format` in error message code follow-up of rust-lang#111633
…sage-code, r=oli-obk Avoid `&format` in error message code follow-up of rust-lang#111633
Some error message cleanups. Best reviewed one commit at a time.
r? @davidtwco