Bad codegen with functions returning `Result`.
Open
@el-ev is already working on this.
Since May 11, 2026.
A-LLVM
C-bug
I-slow
llvm-fixed-upstream
needs-triage
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
https://godbolt.org/z/WGK9WTKec
type Result<T> = core::result::Result<T, u32>;
// ^--- note: all other integer types compile as expected
fn map<T, F, U>(value: Result<T>, op: F) -> Result<U>
where
F: FnOnce(T) -> U
{
value.map(op)
}
pub fn assign(val: [u8; 4], out: &mut u32) -> Result<()> {
let val = map(Ok(val), u32::from_le_bytes)?;
*out = val;
Ok(())
}
I expected to see this:
example[91f12ae00899f36c]::assign:
mov dword ptr [rsi], edi
xor eax, eax
ret
Instead, this happened:
example[91f12ae00899f36c]::assign:
mov eax, edi
shr eax, 24 ; elaborate no-op
shl edi, 8 ; elaborate no-op
shrd edi, eax, 8 ; elaborate no-op
; edi = edi (when the call started)
mov dword ptr [rsi], edi
xor eax, eax
ret
Meta
rustc --version --verbose:
nightly on godbolt
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.
Assessment
This issue has not been assessed yet.