Arithmetic overflow is suppressed by taking a reference to a variable
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This code does not throw arithmetic_overflow at compile time:
fn no_error() -> u8 {
let a: u8 = 20;
let b: u8 = 32;
let _ = &a;
a * b
}
But this code does:
fn errors() -> u8 {
let a: u8 = 20;
let b: u8 = 32;
a * b
}
It seems that borrowing one of the operands suppresses arithmetic_overflow.
Perhaps related to this: https://github.com/rust-lang/rust/issues/104578
Meta
rustc --version --verbose:
rustc 1.91.1 (ed61e7d7e 2025-11-07)
binary: rustc
commit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb
commit-date: 2025-11-07
host: aarch64-apple-darwin
release: 1.91.1
LLVM version: 21.1.2
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
Start by reproducing both Rust snippets with the reported rustc version and compare their compile-time diagnostics, then read the related issue #104578 for context on overflow analysis. No source file or test is named; done means identifying the borrow-sensitive behavior, correcting it, and adding a regression test that verifies the overflow is consistently reported.
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
- 35/100