-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Explain one-past-the-end pointer in std library #138976
Conversation
(Not a libs reviewer, just a drive-by remark) |
I think this is the wrong place to add this remark. I think the existing docs are correct, just confusingly worded, specifically this part on
I believe that "the range between self and the result" is meant to be a half-open range, so all the bytes up to, but not including the result must be within the bounds of the allocated object. |
The original documentation was correct, it just wasn't clear about this boundary case, so that caused the confusion. There seems to be ambiguity in what different people understand. The additions were just to add explanations to alleviate the confusion. : ) Do you have any good suggestions for modifications? @lolbinarycat |
For one, I don't think this should be addressed under allocated object, since by my reading this has nothing to do with the definition of an allocated object. Additionally, calling a pointer valid has a very specific meaning, which has to do with if you can dereference it, so "valid, but you can't dereference it" doesn't really make sense. I think something like this would be good (additions italicized):
We can then clarify the generality of the example later on:
I'm not on t-libs, so ultimately I have no authority on this (and maybe we should wait to see what someone from t-libs thinks about this), but I did rewrite the "Pointer to reference conversion" section, so I have a bit of experience with pointer semantics. |
I'm pretty sure t-libs is actually the wrong team for this. @rust-lang/opsem |
library/core/src/ptr/const_ptr.rs
Outdated
@@ -388,6 +388,12 @@ impl<T: ?Sized> *const T { | |||
/// bounds of that allocated object. In particular, this range must not "wrap around" the edge | |||
/// of the address space. | |||
/// | |||
/// * Note that the special case of "one-past-the-end" pointers is explicitly allowed: a pointer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not using "one-past-the-end" terminology in Rust (I think it's terrible terminology).
Also, as far as I know all the existing docs already handle this properly.
Correct. Happy for suggestions for how to clarify this, but I think calling this "past the end" is needlessly confusing. The pointer is not "past" the end, it is at the end.
👍 , the confusion is entirely around the |
@xizheyin sounds like the only change that is needed is the "(not including the result itself)" line I mentioned earlier. |
Make sense! Thank you for your help. I will revise this PR. @lolbinarycat @RalfJung |
I don't think that's better than what we have now. I'd rather state explicitly that when we talk about a "range" (as we already do), we mean a |
Yeah, that might make more sense, since the allocated object docs are also in terms of ranges. |
Thank you. I've revised this submission to add a sentence of explanation. That doesn't seem to be causing any confusion. Does that make sense? @lolbinarycat @RalfJung |
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
LGTM, thanks. :) @bors r+ rollup |
OH, I just squashed the commits, will it matter? |
It's fine, this just kicked the PR out of the queue so I have to put it back in. :) @bors r+ rollup |
Thanks, I learned a lot. 😊 |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#138976 (Explain one-past-the-end pointer in std library) - rust-lang#139052 (Put pin!() tests in the right file.) - rust-lang#139058 (Fix formatting nit in process.rs) - rust-lang#139063 (Fix TAIT & ATPIT feature gating in the presence of anon consts) - rust-lang#139065 (Miri subtree update) - rust-lang#139069 (`io::Take`: avoid new `BorrowedBuf` creation in some case) - rust-lang#139075 (Do not treat lifetimes from parent items as influencing child items) - rust-lang#139079 (tracking autodiff files via triagebot.toml) Failed merges: - rust-lang#139044 (bootstrap: Avoid cloning `change-id` list) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#138976 - xizheyin:issue-138969, r=RalfJung Explain one-past-the-end pointer in std library Closing rust-lang#138969 r? libs
Explain one-past-the-end pointer in std library Closing rust-lang#138969 r? libs
Fixes #138969
r? libs