Skip to content

#![deny(unsafe_op_in_unsafe_fn)] in libstd #73904

Closed

Description

@LeSeulArtichaut

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.

cc @nikomatsakis @RalfJung

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

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    on Jun 30, 2020
  2. euclio commented on Jun 30, 2020

    @euclio
    Contributor

    I'd like to work on sys/unix.

  3. eltonlaw commented on Jul 1, 2020

    @eltonlaw
    Contributor

    I'd like to work on fs.rs

  4. ryr3 commented on Jul 1, 2020

    @ryr3
    Contributor

    I'd like to take up net/tcp.rs

  5. added a commit that references this issue on Jul 1, 2020
  6. added 3 commits that reference this issue on Jul 2, 2020
  7. hellow554 commented on Jul 2, 2020

    @hellow554
    Contributor

    Took care of process.rs in #73955

    What do you expect for primitive_docs.rs?

  8. 49 remaining items

  9. added
    E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.
    and removed
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
    on Oct 22, 2020
  10. Mark-Simulacrum commented on Oct 22, 2020

    @Mark-Simulacrum
    Member

    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.

  11. added 3 commits that reference this issue on Oct 26, 2020
  12. added a commit that references this issue on Nov 6, 2020
  13. added 2 commits that reference this issue on Nov 6, 2020
  14. removed their assignment
    on Jun 2, 2021
  15. RalfJung commented on May 12, 2024

    @RalfJung
    Member

    @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?

  16. carbotaniuman commented on May 12, 2024

    @carbotaniuman
    Contributor

    Feel free to take my name off, I think I put my name on before a hiatus and I don't remember this anymore.

  17. workingjubilee commented on Dec 11, 2024

    @workingjubilee
    Member

    The initial task list described in this issue has been completed or made out-of-date.

    The rest is tracked in #127747

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCE-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions