-
Notifications
You must be signed in to change notification settings - Fork 184
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
Make ZeroVec have a niche via NonNull #4491
Conversation
fb2ecf1
to
08af4f0
Compare
// Safety: `ptr` comes from Vec::as_mut_ptr, which says: | ||
// "Returns an unsafe mutable pointer to the vector’s buffer, | ||
// or a dangling raw pointer valid for zero sized reads" | ||
buf: unsafe { NonNull::new_unchecked(slice) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this safety comment valid? If the vector is empty, is it guaranteed that the dangling pointer is non-null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ @Manishearth you approved the PR but can you confirm my question about the dangling pointer being non-null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is.
Is this good? Gives us a niche so that
Option<ZeroVec>
doesn't add a whole word.