Skip to content

experiment: Require safety comments in all of std & alloc - #160824

Draft
nia-e wants to merge 2 commits into
rust-lang:mainfrom
nia-e:std-safety-comments
Draft

experiment: Require safety comments in all of std & alloc#160824
nia-e wants to merge 2 commits into
rust-lang:mainfrom
nia-e:std-safety-comments

Conversation

@nia-e

@nia-e nia-e commented Aug 9, 2026

Copy link
Copy Markdown
Member

cc @workingjubilee @joshtriplett, per discussion in Zulip.

this is... awful, but not as awful as expected :D it'd also cause a lot of conflicts. i'm scared of how many CODEOWNERS might be triggered

@rustbot rustbot added O-android Operating system: Android O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) O-hermit Operating System: Hermit O-itron Operating System: ITRON O-linux Operating system: Linux O-netbsd Operating system: NetBSD O-redox Operating system: Redox, https://www.redox-os.org/ O-SGX Target: SGX O-solaris Operating system: Solaris O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 9, 2026
@nia-e nia-e removed O-windows Operating system: Windows O-linux Operating system: Linux O-android Operating system: Android O-netbsd Operating system: NetBSD O-wasm Target: WASM (WebAssembly), http://webassembly.org/ S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. O-redox Operating system: Redox, https://www.redox-os.org/ O-solaris Operating system: Solaris O-SGX Target: SGX O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-hermit Operating System: Hermit labels Aug 9, 2026
@nia-e nia-e added O-windows Operating system: Windows O-linux Operating system: Linux O-android Operating system: Android O-netbsd Operating system: NetBSD O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-redox Operating system: Redox, https://www.redox-os.org/ O-solaris Operating system: Solaris O-SGX Target: SGX O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-hermit Operating System: Hermit O-itron Operating System: ITRON O-solid Operating System: SOLID O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) and removed O-itron Operating System: ITRON O-solid Operating System: SOLID O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) labels Aug 9, 2026
@workingjubilee

Copy link
Copy Markdown
Member

We have CODEOWNERS?

@nia-e

nia-e commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

we have configs for teams to get pinged when certain files are touched. close enough

@clarfonthey

Copy link
Copy Markdown
Contributor

I think, for the sake of this being reasonable to merge at all, we should probably split this into multiple pieces.

Also, perhaps starting with alloc would be best?

@nia-e

nia-e commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

alloc is reasonable to start. a lot of std excepting os and sys would be actually doable manually. i'd also want a check-in from libs more broadly that we want to go this direction, so i'd let the idea cook for a bit before i'd want to merge anything

@clarfonthey

Copy link
Copy Markdown
Contributor

I feel like offering up a PR with just alloc would be a good test, since some folks mentioned it might increase noise, and it'd be a good example for people to play with and see if that's actually the case.

sys and os are substantially larger and messier, so, they'd probably be harder to gauge. There's already a lot of duplication we still need to scale back.

@ChrisDenton ChrisDenton Aug 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file is generated from windows-bindgen so shouldn't be edited. But the good news is that, since Default is now implemented on pointers, the unsafe will be going away in the next version of windows-bindgen.

View changes since the review

Comment on lines 336 to +339
// Safety: We only touch lock_count when we own the inner mutex.
// Additionally, we only call `self.owner.set()` while holding
// the inner mutex, so no two threads can call it concurrently.
// SAFETY: Untriaged.

@y21 y21 Aug 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two safety comments here now

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fair. I did all of this with just a regex, not intending to merge as-is ^^ there's very likely a lot of cases like this

_ => {
// SAFETY: Untriaged.
unsafe {
cvt(libc::pipe(fds.as_mut_ptr()))?;

@y21 y21 Aug 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Formatting seems a little off here

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is an unfortunate side-effect of macro formatting; not even indenting gets done right.

@rust-bors

rust-bors Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #160954) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-android Operating system: Android O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) O-hermit Operating System: Hermit O-itron Operating System: ITRON O-linux Operating system: Linux O-netbsd Operating system: NetBSD O-redox Operating system: Redox, https://www.redox-os.org/ O-SGX Target: SGX O-solaris Operating system: Solaris O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows 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.

6 participants