Skip to content

[lint: unsafe_in_unsafe_fn] A lint which triggers on unsafe operations in unsafe fn #69270

Open

Description

@Centril

As a follow up to fixing #69173 via #69245, we would like to see a lint, starting as allow-by-default which would trigger on the following situation:

#![warn(unsafe_in_unsafe_fn)]

unsafe fn foo() {} // Stand-in for any unsafe operation.
unsafe fn bar() {
    foo();
    //~^ WARN unsafe operation directly in `unsafe fn`
    //~| HELP move the operation into an `unsafe { ... }` block.
}

Eventually, over time, we would like to consider moving this lint to be warn-by-default, but we would like to give the ecosystem time to adapt before doing so. We have not discussed what the timescale of "eventually" entails.

Context (this has already been tentatively accepted by the language team in meetings, though not FCP):

cc @rust-lang/lang @RalfJung

This issue has been assigned to @LeSeulArtichaut via this comment.

Activity

  1. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Feb 18, 2020
  2. LeSeulArtichaut commented on Feb 19, 2020

    @LeSeulArtichaut
    Contributor

    Working on this.
    @rustbot claim

  3. self-assigned this
    on Feb 19, 2020
  4. programmerjake commented on Mar 27, 2020

    @programmerjake
    Member

    This would be very useful for implementing an extensive C FFI API since most of the functions are unsafe externally but the functions' bodies don't necessarily need any unsafe code. Once this is stabilized, I will definitely be using this in Kazan, the Vulkan driver I'm writing.

  5. RalfJung commented on Mar 29, 2020

    @RalfJung
    Member

    I updated the RFC to discuss the new proposed lint and the interaction with the "unnecessary unsafe" lint. See rust-lang/rfcs#2585 (comment).

  6. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Jul 24, 2020
  7. removed their assignment
    on Jan 27, 2022
  8. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    and removed
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Dec 21, 2024
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

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler 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