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

Box::into_raw doesn't document that the returned pointer will not be null #52806

Closed
jonas-schievink opened this issue Jul 28, 2018 · 3 comments
Closed
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@jonas-schievink
Copy link
Contributor

The existence of the unstable Box::into_raw_non_null kind of hints that this is the case (as does an understanding of how Box internally works), but it would be nice for unsafe code to actually guarantee this.

@kennytm kennytm added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Jul 28, 2018
@estk
Copy link
Contributor

estk commented Aug 7, 2018

@kennytm and @jonas-schievink I started looking into this and I'd be happy to update the docs. After having a look over the code however I was a bit confused about how if at all the docs could be improved.

This line:

/// Consumes the `Box`, returning the wrapped pointer as `NonNull<T>`.

To me, it seems sufficient to indicate that the pointer will not be null, @jonas-schievink how do you think it should be improved?

@sfackler
Copy link
Member

sfackler commented Aug 8, 2018

Box always points to a valid allocation, and null is not a valid allocation.

@jonas-schievink
Copy link
Contributor Author

@estk That line is for into_raw_non_null, not into_raw. For the latter, just an additional sentence stating that the returned pointer is guaranteed to not be null should be enough - maybe adding that the pointer will be properly aligned is a good idea, too.

kennytm added a commit to kennytm/rust that referenced this issue Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

4 participants