Skip to content

cast_possible_wrap false negative #17755

Description

@masmullin2000

Summary

I think there is an issue somewhere between shas

2c5e3d3

and

01dfd31

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.59s

Instead, 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.04s

Version

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.8

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions