`fmt::Arguments::as_statically_known_str` optimizes poorly
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I compiled this code with -Copt-level=3
#![feature(fmt_internals)]
#![expect(internal_features)]
#[unsafe(no_mangle)]
fn foo(a: std::fmt::Arguments<'_>) -> Option<&str> {
a.as_statically_known_str()
}
I got the following assembly:
foo:
mov rdx, rsi
shr rdx
xor eax, eax
ret
This function should just optimize to returning None, so the first two instructions seem extraneous.
I am unsure if this has any impact on code using the actual fmt public API.
Meta
Reproducible on godbolt with version:
rustc 1.95.0-nightly (7f99507f5 2026-02-19)
binary: rustc
commit-hash: 7f99507f57e6c4aa0dce3daf6a13cca8cd4dd312
commit-date: 2026-02-19
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0
Internal compiler ID: nightly
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Rust 1.95.0-nightly example on Godbolt and inspect the generated assembly for fmt::Arguments::as_statically_known_str. Start by tracing that entry point through the compiler sources and its optimization behavior. Done means the unnecessary instructions are eliminated for this case, with relevant compiler tests covering the result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100