Stream: t-lang/wg-unsafe-code-guidelines

Topic: NonNull and aliasing model


Elichai Turkel (Apr 18 2020 at 12:44, on Zulip):

Hi,
I'm reading https://github.com/rust-lang/unsafe-code-guidelines/issues/194, and I have a question, in that thread people keep talking about NonNull allowing aliasing.
e.g:

We replace the Vec with a deconstructed vector; it's equivalent but uses NonNull for its pointer, so it's an aliasable owner.

the NonNull to opt out of uniqueness;

Is there something special about NonNull that allows aliasing where "regular" raw pointers don't? or am I misunderstanding this?

Thanks!

Amanieu (Apr 18 2020 at 14:38, on Zulip):

AFAIK NonNull has the same semantics as a raw pointer.

Amanieu (Apr 18 2020 at 14:44, on Zulip):

The unstable Unique<T> pointer type may have additional aliasing constraints, but it's not very clear to me. And apparently Box<T> has the same restrictions since it contains a Unique<T>.

RalfJ (Apr 19 2020 at 07:43, on Zulip):

Amanieu said:

AFAIK NonNull has the same semantics as a raw pointer.

agreed

RalfJ (Apr 19 2020 at 07:44, on Zulip):

Amanieu said:

The unstable Unique<T> pointer type may have additional aliasing constraints, but it's not very clear to me. And apparently Box<T> has the same restrictions since it contains a Unique<T>.

Technically right now, Box has special constraints, but Unique does not. However this is something we certainly want to explore in the future. I'd very much like to find a way to make Unique special, and get corresponding optimizations for Vec.

Last update: Jun 05 2020 at 22:40UTC