Summary
Arithmetic side effects lint is not able to realise overflow is impossible given operators of a u32 constant and a u16 variable.
Lint Name
clippy::arithmetic-side-effects
Reproducer
I tried this code:
fn main() {
let sram = Sram { id: 99 };
let x: u32 = 0xf3010000 + sram.id() as u32;
println!("Hello, 0x{x:x}");
}
struct Sram {
id: u16,
}
impl Sram {
fn id(&self) -> u16 {
self.id
}
}
I saw this happen:
warning: arithmetic operation that can potentially result in unexpected side-effects
--> src/main.rs:3:18
|
3 | let x: u32 = 0xf3010000 + sram.id() as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects
= note: requested on the command line with `-W clippy::arithmetic-side-effects`
warning: `clippy-bug` (bin "clippy-bug") generated 1 warning
The warning is unnecessary cautious: The first operand is a constant small enough that it can never overflow by adding a u16 or in this case a value which is extended from an u16.
Version
rustc -Vv
rustc 1.93.0 (254b59607 2026-01-19)
binary: rustc
commit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c
commit-date: 2026-01-19
host: x86_64-unknown-linux-gnu
release: 1.93.0
LLVM version: 21.1.8
I reproduced on nightly too:
cargo +nightly clippy -- -W clippy::arithmetic-side-effects --version
clippy 0.1.97 (8b03437a8f 2026-05-12)
Additional Labels
No response
Summary
Arithmetic side effects lint is not able to realise overflow is impossible given operators of a u32 constant and a u16 variable.
Lint Name
clippy::arithmetic-side-effects
Reproducer
I tried this code:
I saw this happen:
The warning is unnecessary cautious: The first operand is a constant small enough that it can never overflow by adding a u16 or in this case a value which is extended from an u16.
Version
Additional Labels
No response