cast_possible_wrap false negative
Author: masmullin2000Created Sep 18, 2026Updated Sep 18, 2026
LabelsC-bugI-false-negative
Summary
I think there is an issue somewhere between shas
2c5e3d3c5ce9ff2a2d77fc7481c612a843cb008a
and
01dfd311b7cd4853e07d715bc17ec27f3ab06014
from https://github.com/rust-lang/rust-clippy/pull/16866/commits
Lint Name
cast_possible_wrap
Reproducer
I tried this code:
use libc::pid_t;
type MM = i32;
fn main() {
let x: libc::pid_t = std::process::id() as pid_t;
let w: MM = std::process::id() as MM;
let y: i32 = std::process::id() as i32;
println!("Hello, world {x}:{y}:{w}!");
}I expected to see this happen:
warning: casting `u32` to `i32` may wrap around the value
--> src/main.rs:6:26
|
6 | let x: libc::pid_t = std::process::id() as pid_t;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `std::process::id().cast_signed()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap
= note: `-W clippy::cast-possible-wrap` implied by `-W clippy::pedantic`
= help: to override `-W clippy::pedantic` add `#[allow(clippy::cast_possible_wrap)]`
warning: casting `u32` to `i32` may wrap around the value
--> src/main.rs:8:17
|
8 | let w: MM = std::process::id() as MM;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `std::process::id().cast_signed()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap
warning: casting `u32` to `i32` may wrap around the value
--> src/main.rs:10:18
|
10 | let y: i32 = std::process::id() as i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `std::process::id().cast_signed()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap
warning: `id` (bin "id") generated 3 warnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.59sInstead, this happened:
warning: casting `u32` to `i32` may wrap around the value
--> src/main.rs:8:17
|
8 | let w: MM = std::process::id() as MM;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `std::process::id().cast_signed()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap
= note: `-W clippy::cast-possible-wrap` implied by `-W clippy::pedantic`
= help: to override `-W clippy::pedantic` add `#[allow(clippy::cast_possible_wrap)]`
warning: casting `u32` to `i32` may wrap around the value
--> src/main.rs:10:18
|
10 | let y: i32 = std::process::id() as i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `std::process::id().cast_signed()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap
warning: `id` (bin "id") generated 2 warnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04sVersion
rustc 1.98.1 (48a229cea 2026-09-01)
binary: rustc
commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985
commit-date: 2026-09-01
host: x86_64-unknown-linux-gnu
release: 1.98.1
LLVM version: 22.1.8Source: rust-lang/rust-clippy