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

Tracking issue for Box::into_raw_non_null #47336

Open
SimonSapin opened this Issue Jan 10, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@SimonSapin
Contributor

SimonSapin commented Jan 10, 2018

This API was introduced in #46952:

impl<T: ?Sized> Box<T> {
    pub fn into_raw_non_null(b: Box<T>) -> NonNull<T> { /* … */ }
}

It is intended as an eventually-stable replacement for Box::into_unique, since there is no plan to stabilize Unique<T> at the moment.

See also discussion at #27730.

@SimonSapin

This comment has been minimized.

Contributor

SimonSapin commented Mar 17, 2018

It would be nice for this method to be an impl of the From trait instead, but coherence does not allow it since ptr::NonNull and Box are defined in separate crates. Having an Into impl without the corresponding From impl was frowned upon in the PR discussion.

This method can be replaced with unsafe { NonNull::new_unchecked(Box::into_raw(b)) }. This unsafe block is sound because Box is never null. Having a dedicated API removes the need for that unsafe block.

So while we can live without it, I’m still in favor of stabilizing this. It’s small and won’t be a maintenance burden.

@nvzqz

This comment has been minimized.

Contributor

nvzqz commented Apr 9, 2018

I'm in favor of Box::into_non_null since we have Box::into_unique. Feels more consistent that way.

@SimonSapin

This comment has been minimized.

Contributor

SimonSapin commented Apr 9, 2018

@nvzqz Box::into_unique is unstable though, and I don’t know if it (or Unique) well even be stabilized.

@nvzqz

This comment has been minimized.

Contributor

nvzqz commented Apr 10, 2018

I'm acutely aware it is. If we choose to stabilize both, then their names should be considered against each other regarding convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment