Skip to content
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

Merged
merged 4 commits into from
Dec 25, 2023
Merged

Conversation

sffc
Copy link
Member

@sffc sffc commented Dec 23, 2023

Is this good? Gives us a niche so that Option<ZeroVec> doesn't add a whole word.

Manishearth
Manishearth previously approved these changes Dec 23, 2023
Comment on lines +320 to +323
// 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) },
Copy link
Member Author

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?

Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.

@sffc sffc merged commit ce906e6 into unicode-org:main Dec 25, 2023
29 checks passed
@sffc sffc deleted the nonnull-zerovec branch December 25, 2023 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants