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

Reword clarification on lifetime for ptr->ref safety docs #96136

Merged
merged 1 commit into from
Apr 18, 2022

Conversation

thomcc
Copy link
Member

@thomcc thomcc commented Apr 17, 2022

I believe the current wording of the safety comment is somewhat misleading, and that this is more accurate. Suggested by @CAD97 in this thread on the topic https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Lifetime.20of.20reference.20pointer.20docs.20issue

Just to check that this is correct, CC @RalfJung.

I suppose it's open for interpretation as to whether or not this is more clear. I think it is.

@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Apr 17, 2022
@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 17, 2022
Copy link
Contributor

@CAD97 CAD97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously I think this is a positive change.

@RalfJung
Copy link
Member

I might have written those previous comments, and I basically wanted to be on the safe side -- but I agree that, with high probability, the aliasing model Rust will end up with will care about how references are actually used, not about their lifetime annotations.

There are some wrinkles here though -- the word "exists" is doing a lot of work here, and it is not very precise. It seems to be reasonable cautious though, the actual rules are likely even less strict (more like "while the reference is being used to access memory, and also while any functions that received this reference as an argument are still running", or so).

@RalfJung
Copy link
Member

So, r=me, unless you want to wait for someone from the libs team.

@thomcc
Copy link
Member Author

thomcc commented Apr 17, 2022

Hm, I probably should have requested your review, 🤷. But it doesn't hurt for someone to sign off that "yes, this makes more sense than the previous" I suppose.

@m-ou-se
Copy link
Member

m-ou-se commented Apr 18, 2022

"while this reference exists" is not very precise; one could argue it doesn't cover copies of that reference. (But making it more precise probably also makes it needlessly more confusing though.)

@bors r=RalfJung

@bors
Copy link
Contributor

bors commented Apr 18, 2022

📌 Commit be30e40 has been approved by RalfJung

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 18, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#96032 (Update books)
 - rust-lang#96136 (Reword clarification on lifetime for ptr->ref safety docs)
 - rust-lang#96143 (Fix snapshot --bless not working anymore in htmldocck)
 - rust-lang#96148 (Use revisions instead of nll compare mode for `/self/` ui tests)
 - rust-lang#96156 (Replace u8to64_le macro with u64::from_le_bytes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a6ad139 into rust-lang:master Apr 18, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants