Repository navigation
Description
The goal of this effort is to #![deny(unsafe_op_in_unsafe_fn)] in all of libstd, as proposed in rust-lang/compiler-team#317. This means enclosing unsafe operations in unsafe functions inside unsafe blocks, and documenting them as much as possible.
However, as libstd contains more than 100,000 lines (!!!) and 600 unsafe functions, this should be done step by step, and by multiple people. This issue is meant as a way of tracking and synchronizing progress.
Mentoring instructions (or rather, suggested workflow)
Please first leave a comment here stating that you want to work on file xxx.rs or module xxx, to make sure that this implements Sync.
You'll first want to add a #![deny(unsafe_op_in_unsafe_fn)] attribute in the scope you'll be working on.
Then, add unsafe blocks around unsafe operations in unsafe functions. These unsafe operations can be found either by searching for unsafe fns, or by running ./x.py check src/libstd and looking at the errors.
When adding an unsafe block, try to explain why it is safe in a safety comment before the unsafe block. This should look like:
// SAFETY: explain why `unsf` is safe here...
unsafe {
unsf();
}Example PRs: #72709 (for liballoc) and #73622 (for libcore)
TODO list
-
alloc.rs(@poliorcetics, Deny unsafe operations in unsafe functions in libstd/alloc.rs #74333) -
fs.rs(@eltonlaw,#[deny(unsafe_op_in_unsafe_fn)]in libstd/fs.rs #73909) -
panicking.rs(@poliorcetics, Std panicking unsafe block in unsafe fn #74200) -
path.rs(@hellow554, deny(unsafe_op_in_unsafe_fn) in libstd/path.rs #73963) -
primitive_docs.rs -
process.rs(@hellow554, deny(unsafe_op_in_unsafe_fn) in libstd/process.rs #73955) -
sys_common/(@LeSeulArtichaut, Deny unsafe ops in unsafe fns instd::sys_common#73928) -
net/tcp.rs(@ryr3, libstd/net/tcp.rs: #![deny(unsafe_op_in_unsafe_fn)] #73962) -
io/(@ryr3) -
ffi/c_str.rs(@poliorcetics, deny(unsafe_op_in_unsafe_fn) in libstd/ffi/c_str.rs #74062) -
(@poliorcetics, Deny unsafe operations in unsafe fns in libstd/sync/ #74278)sync/mpsc -
thread/(@poliorcetics, Std/thread: deny unsafe op in unsafe fn #74225) -
sys/-
sys/cloudabi(@chansuke,#[deny(unsafe_op_in_unsafe_fn)]in sys/cloudabi #75115) -
sys/hermit(@maekawatoshiki,#![deny(unsafe_op_in_unsafe_fn)]in sys/hermit #74979) -
sys/sgx(@Caduser2020,#[deny(unsafe_op_in_unsafe_fn)]in sys/sgx #77346) -
sys/unix(@euclio) -
sys/unsupported(@m-ou-se, Remove unsafety from sys/unsupported and add deny(unsafe_op_in_unsafe_fn). #77722) -
sys/vxworks -
sys/wasm(@chansuke,#[deny(unsafe_op_in_unsafe_fn)]in sys/wasm #74477) -
sys/wasi(@Amjad50, Applied#![deny(unsafe_op_in_unsafe_fn)]in library/std/src/wasi #75971) -
sys/windows(unclaimed, previous attempt: Apply#![deny(unsafe_op_in_unsafe_fn)]to sys/windows #76676)
-
Activity
euclio commentedon Jun 30, 2020
I'd like to work on sys/unix.
eltonlaw commentedon Jul 1, 2020
I'd like to work on
fs.rsryr3 commentedon Jul 1, 2020
I'd like to take up
net/tcp.rsRollup merge of rust-lang#73909 - eltonlaw:unsafe-libstd-fs-rs, r=sfa…
Rollup merge of rust-lang#73909 - eltonlaw:unsafe-libstd-fs-rs, r=sfa…
Rollup merge of rust-lang#73909 - eltonlaw:unsafe-libstd-fs-rs, r=sfa…
Rollup merge of rust-lang#73909 - eltonlaw:unsafe-libstd-fs-rs, r=sfa…
hellow554 commentedon Jul 2, 2020
Took care of process.rs in #73955
What do you expect for
primitive_docs.rs?49 remaining items
Mark-Simulacrum commentedon Oct 22, 2020
I have adjusted the E- tag here to E-hard, because for the most part, correctly checking the requirements and determining the appropriate safety comment to write is not an easy task. It might be a medium task (unclear), but it feels hard to me.
Rollup merge of rust-lang#74477 - chansuke:sys-wasm-unsafe-op-in-unsa…
Rollup merge of rust-lang#74477 - chansuke:sys-wasm-unsafe-op-in-unsa…
Rollup merge of rust-lang#74477 - chansuke:sys-wasm-unsafe-op-in-unsa…
Rollup merge of rust-lang#74979 - maekawatoshiki:fix, r=Mark-Simulacrum
Rollup merge of rust-lang#74979 - maekawatoshiki:fix, r=Mark-Simulacrum
Rollup merge of rust-lang#74979 - maekawatoshiki:fix, r=Mark-Simulacrum
RalfJung commentedon May 12, 2024
@LeSeulArtichaut @ryr3 @euclio @carbotaniuman you are currently "registered" at the top of this issue for various parts of std to be ported to
unsafe_op_in_unsafe_fn. However, there doesn't seem to have been progress in a while -- do you still plan to pick this up, or can I remove your names from the issue so others can pick it up if they want to?carbotaniuman commentedon May 12, 2024
Feel free to take my name off, I think I put my name on before a hiatus and I don't remember this anymore.
workingjubilee commentedon Dec 11, 2024
The initial task list described in this issue has been completed or made out-of-date.
The rest is tracked in #127747