Skip to content

zst_offset not warning for NonNull #16887

@esthedebeste

Description

@esthedebeste

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)

Metadata

Metadata

Assignees

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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions