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

It should be possible to dereference NonNull in unsafe blocks #48277

Closed
joshlf opened this issue Feb 16, 2018 · 4 comments
Closed

It should be possible to dereference NonNull in unsafe blocks #48277

joshlf opened this issue Feb 16, 2018 · 4 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@joshlf
Copy link
Contributor

joshlf commented Feb 16, 2018

In porting some code from *mut T to NonNull<T>, I've been having to add a lot of .as_ptr() conversions in order to dereference (i.e., *ptr vs *ptr.as_ptr()). It'd be great it were possible to dereference NonNull directly when in unsafe blocks.

My guess is that this would require adding some sort of UnsafeDeref/UnsafeDerefMut traits and making the compiler know about them, so this is probably no simple task.

@kennytm kennytm added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Feb 16, 2018
@Lokathor
Copy link
Contributor

Absolutely, and raw pointers should also get the benefits of a Deref-like trait with deref-coercion magic. If you're already in an unsafe block you already accepted the risks.

@scottmcm
Copy link
Member

This reminds me of rust-lang/rfcs#2237, just with unsafe instead of const...

@Lokathor
Copy link
Contributor

I actually posted in that RFC, but here is good too if that gets things implemented and usable faster to do just this one small trait compared to the whole system that would be that rfc

@steveklabnik
Copy link
Member

Triage:

My guess is that this would require adding some sort of UnsafeDeref/UnsafeDerefMut traits and making the compiler know about them, so this is probably no simple task.

Yep, and that puts this in RFC territory, so let's close this.

n.b.: I know that @withoutboats has also wished for more ergonomics around NonNull, and unsafe code in general, but would prefer to work on it in a holistic fashion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants