-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
pub fn test() -> String {
let input = "abc";
format!("pre:{}", input)
}
I expected/hoped this would be optimized down to "pre:abc".to_string()
, as it does when a string literal is written inline as an argument to format!
. However, the assembly output shows "abc"
and "pre:"
as separate strings. (Note that in the inline case, there is no string at all; the optimized form inlines the string data as integer constants.)
(Occurs in both stable 1.88.0 and nightly 2025-07-21.)
Motivated by using std::any::type_name
for logging and being mildly surprised it wasn't statically resolved, though I realize that may have a few layers beyond this one.
Metadata
Metadata
Assignees
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.