Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Centril opened this issue Feb 18, 2020 · 3 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Feb 18, 2020

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.

@Centril Centril added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 18, 2020
@LeSeulArtichaut
Copy link
Contributor

Working on this.
@rustbot claim

@rustbot rustbot self-assigned this Feb 19, 2020
@programmerjake
Copy link
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.

@RalfJung
Copy link
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).

@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 24, 2020
@dtolnay dtolnay assigned LeSeulArtichaut and unassigned rustbot Jan 27, 2022
@LeSeulArtichaut LeSeulArtichaut removed their assignment Jan 27, 2022
@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants