-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Request: add
, sub
, and offset
for NonNull
#90549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think |
let ptr = usize::MAX as *const u8;
unsafe {
assert_eq!(ptr.add(1), core::ptr::null());
} |
The standard rules of add/sub/offset would still apply, specifically that the calculation does not go outside of an allocation or one byte past the end of an allocation, and also that the calculation does not wrap within the address space. So it would already be UB to |
Seems to be a duplicate of #72429. |
Closing this as duplicate of #72429 |
Currently, offsetting a non-null pointer is quite cumbersome. It would be better if these pointer methods were provided directly on the NonNull type instead of having to get the inner pointer, do the change, and then call NonNull::new_unchecked on that output.
The text was updated successfully, but these errors were encountered: