-
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
Specialize ToString implementation for fmt::Arguments #111168
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@rustbot label +T-libs-api -T-libs |
What is the user-visible impact of this specialization? Naively it seems like it should just be an internal optimization? @rustbot author |
Having generic This is somewhat how I found that it was not specialized: enum Error {
Custom(String),
}
impl Error {
// or T: ToString
fn new<T: std::fmt::Display>(t: T) -> Self {
Self::Custom(t.to_string())
}
}
fn main() {
let stuff = 1234;
let _a = Error::new(stuff);
let _b = Error::new(format_args!("Format args: {stuff}"));
let _c = Error::new(format!("Format: {stuff}"));
let _d = Error::new("Str");
} Using |
When I say user visible I mean e.g. a test case that would fail before this change, but works after, or similar. If this is purely about performance then that's generally easier to land, as it's not something we would be blocked on reverting if we decide to go a different path in the future. |
@rustbot review |
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
Generates far fewer instructions by formatting into a String with
fmt::format
directly instead of going through thefmt::Display
impl. This change is insta-stable.