Skip to content

Tweak Layout::from_size_align_unchecked safety comment - #163288

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
ultrabear:ultrabear/layout-from-size-align
Sep 25, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
ultrabear:ultrabear/layout-from-size-align

Conversation

@ultrabear

Copy link
Copy Markdown
Contributor

This slightly tweaks wording of the Safety "contract" of Layout::from_size_align_unchecked. In my opinion, safety comments on function documentation should specify "here is how to safely use this function" rather than the more indirect form of "this function is unsafe because ...".

In this case the current docs are clear to me on how to use the function properly, but Its very uncommon that I see the safety comment worded in this sort of roundabout way, and typically when I see it in other crates its a lower quality safety comment that says something like "this function is unsafe because it uses a raw pointer", so I may just associate it with being a more wrong way to write the docs anyways.

Thought it worthwhile to open a PR for it to make it more direct and see what others think about "the right better way to word safety contracts"

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 24, 2026
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 24, 2026
@rustbot

rustbot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

r? @LawnGnome

rustbot has assigned @LawnGnome.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from 6 candidates

@thomcc

thomcc commented Sep 24, 2026

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

⌛ Commit 876f7a0 has been tentatively approved by thomcc. It will be fully approved once PR CI is successful.

@rust-bors

rust-bors Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 876f7a0 has been approved by thomcc

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Sep 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 25, 2026
Rollup of 7 pull requests

Successful merges:

 - #160068 (Preserve explicit register names in inline asm diagnostics)
 - #163239 (Fix applicability level for cfg suggestion)
 - #163025 (make `Complex` ABI GCC-compatible on sparc)
 - #163076 (powerpc64: don't pass unions in FPRs on ELFv1)
 - #163268 ([rustdoc] Correctly check that an item is not `doc(hidden)` with `--generate-link-to-definition`)
 - #163288 (Tweak Layout::from_size_align_unchecked safety comment)
 - #163292 (moving div_ceil() to associated items macro)
@rust-bors
rust-bors Bot merged commit a8c7176 into rust-lang:main Sep 25, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 25, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 25, 2026
Rollup merge of #163288 - ultrabear:ultrabear/layout-from-size-align, r=thomcc

Tweak Layout::from_size_align_unchecked safety comment

This slightly tweaks wording of the Safety "contract" of Layout::from_size_align_unchecked. In my opinion, safety comments on function documentation should specify "here is how to safely use this function" rather than the more indirect form of "this function is unsafe because ...".

In this case the current docs are clear to me on how to use the function properly, but Its very uncommon that I see the safety comment worded in this sort of roundabout way, and typically when I see it in other crates its a lower quality safety comment that says something like "this function is unsafe because it uses a raw pointer", so I may just associate it with being a more wrong way to write the docs anyways.

Thought it worthwhile to open a PR for it to make it more direct and see what others think about "the ~right~ better way to word safety contracts"
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.

4 participants