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

Clarify preconditions of raw size/align methods #103372

Conversation

Jules-Bertholet
Copy link
Contributor

The documentation of the preconditions of mem::size_of_val_raw, mem::align_of_val_raw, and Layout::for_value_raw was overly conservative. This PR resolves that problem.

Discussion: #69835 (comment)

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

rustbot commented Oct 21, 2022

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 @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. 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

@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 Oct 21, 2022
@CAD97
Copy link
Contributor

CAD97 commented Oct 22, 2022

I think it'd perhaps be better worded as something around the shape of

Safety

This function is safe to call if the pointer is valid to reborrow as &T (in which case you could also call size_of_val). Otherwise, the following conditions must hold:

(existing bullet points)

This makes is clearer that "valid for reborrow" is always a sufficient precondition.

@m-ou-se
Copy link
Member

m-ou-se commented Dec 30, 2022

The exception/note about reborrowing as &T now appears at both the top and bottom of the list of conditions, which is a bit confusing. Right now it's basically: "This function is safe to call if {A}. Otherwise: {list of conditions}. Otherwise, {A}."

Isn't just the note at the start (as suggested by CAD97) enough?

@m-ou-se m-ou-se added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 30, 2022
@JohnCSimon
Copy link
Member

@Jules-Bertholet
Ping from triage - can you please address the reviewer's comments?

@Dylan-DPC
Copy link
Member

Closing this as inactive. Feel free to open a new PR if you wish to continue these changes

@Dylan-DPC Dylan-DPC closed this Feb 24, 2023
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. 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