Skip to content

Clarify preconditions of raw size/align methods - #103372

Closed
Jules-Bertholet wants to merge 2 commits into
rust-lang:masterfrom
Jules-Bertholet:raw_size_align_docs_fix
Closed

Clarify preconditions of raw size/align methods#103372
Jules-Bertholet wants to merge 2 commits into
rust-lang:masterfrom
Jules-Bertholet:raw_size_align_docs_fix

Conversation

@Jules-Bertholet

Copy link
Copy Markdown
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

rustbot commented Oct 21, 2022

Copy link
Copy Markdown
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 @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
Copy Markdown
Contributor

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

CAD97 commented Oct 22, 2022

Copy link
Copy Markdown
Contributor

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

m-ou-se commented Dec 30, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown

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

@Dylan-DPC

Copy link
Copy Markdown
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
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 28, 2026
…r=JohnTitor

Clarify preconditions of raw size/align methods

The current documentation doesn't guarantee that these methods are safe to call for pointers derived from references to new unsized types that Rust may add in the future.

Take 2 of rust-lang#103372, wording from @CAD97 in rust-lang#103372 (comment).

Tracking issue: rust-lang#69835
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 28, 2026
…r=JohnTitor

Clarify preconditions of raw size/align methods

The current documentation doesn't guarantee that these methods are safe to call for pointers derived from references to new unsized types that Rust may add in the future.

Take 2 of rust-lang#103372, wording from @CAD97 in rust-lang#103372 (comment).

Tracking issue: rust-lang#69835
rust-timer added a commit that referenced this pull request Jul 28, 2026
Rollup merge of #158893 - Jules-Bertholet:for-pointer-docs, r=JohnTitor

Clarify preconditions of raw size/align methods

The current documentation doesn't guarantee that these methods are safe to call for pointers derived from references to new unsized types that Rust may add in the future.

Take 2 of #103372, wording from @CAD97 in #103372 (comment).

Tracking issue: #69835
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