Skip to content

Possibly a typo on the "What Unsafe Rust Can Do" page? #299

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

Closed
mexus opened this issue Aug 13, 2021 · 5 comments · Fixed by #319
Closed

Possibly a typo on the "What Unsafe Rust Can Do" page? #299

mexus opened this issue Aug 13, 2021 · 5 comments · Fixed by #319

Comments

@mexus
Copy link
Contributor

mexus commented Aug 13, 2021

https://github.com/rust-lang/nomicon/blob/0c7e5bd1428e7838252bb57b7f0fbfda4ec82f02/src/what-unsafe-does.md

Here's a paragraph that caused my confusion:

A reference/pointer is "dangling" if it is null or not all of the bytes it points to are part of the same allocation (so in particular they all have to be part of some allocation). The span of bytes it points to is determined by the pointer value and the size of the pointee type. As a consequence, if the span is empty, "dangling" is the same as "non-null". Note that slices and strings point to their entire range, so it's important that the length metadata is never too large (in particular, allocations and therefore slices and strings cannot be bigger than isize::MAX bytes). If for some reason this is too cumbersome, consider using raw pointers.

So, the first sentence states:

A reference/pointer is "dangling" if it is null or ...

And the sentence about an empty span states:

... if the span is empty, "dangling" is the same as "non-null"

Isn't there a contradiction? Shouldn't it be more like "is the same as null" or "non-danling" in the latter sentence?

Or am I missing something?

Thanks!

@JohnTitor
Copy link
Member

JohnTitor commented Aug 30, 2021

So, if we consider "null pointers ⊂ dangling pointers", the latter sentence should be reworded as you suggested.
Let's trace the history. The latter one was written in 98a71fd, the wording was already confusing as we considered "null pointers ⊂ dangling pointers" in other places (see also some other rewording commits in the related PR).
But rewording the latter might be confusing as "dangling pointers" generally, AFAIK, don't contain "null pointers".
cc @RalfJung you are the original author of it, any thoughts?

@RalfJung
Copy link
Member

RalfJung commented Sep 4, 2021

I think it would be reasonable to say that the null pointer is dangling... or are you saying that is not standard terminology? I never thought much about this, TBH.

@JohnTitor
Copy link
Member

or are you saying that is not standard terminology?

No I don't think (TBH, I'm not sure) it's standard, but after some googling, I think some may want to distinguish "dangling pointers" from "null pointers" from the point of view of "whether it was valid, i.e. pointing to an actual place before". Anyway, if it's not confusing, I'm happy to reword the part as Denis suggested (dangling is the same as "non-null" "null").

@RalfJung
Copy link
Member

I think some may want to distinguish "dangling pointers" from "null pointers" from the point of view of "whether it was valid, i.e. pointing to an actual place before".

But then what about pointers like 16 as *const i32, that are neither null nor have they pointed to an actual place before?

@JohnTitor
Copy link
Member

Hmm, I'm not sure, TBH. Anyway, I'm going just to reword it as mentioned above, I think it's the best way here.

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 a pull request may close this issue.

3 participants