Summary
NonNull<T> is a non-null guaranteeing wrapper on *mut T. It also has add, offset, etc. implementations. These are not checked for NonNull<()>.
Lint Name
zst_offset
Reproducer
I tried this code:
#![warn(clippy::zst_offset)]
use core::ptr::NonNull;
fn main() {
let mut x = 3;
let addr: NonNull<()> = NonNull::new(&mut x as *mut i32 as *mut ()).unwrap();
let addr_plus_one = unsafe { addr.add(1) };
println!("{addr:?} + 1 = {addr_plus_one:?}");
}
playground
I expected to see this happen:
A warning as addr.add(1) is a noop (like in this playground)
Instead, this happened:
No warning
Version
0.1.97 (2026-04-18 0febdbab27)
Summary
NonNull<T>is a non-null guaranteeing wrapper on*mut T. It also hasadd,offset, etc. implementations. These are not checked forNonNull<()>.Lint Name
zst_offset
Reproducer
I tried this code:
playground
I expected to see this happen:
A warning as
addr.add(1)is a noop (like in this playground)Instead, this happened:
No warning
Version