-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New Lint: Unsafe block in safe functions without SAFETY
comment
#7238
Comments
From API guidelines, unsafe functions should be documented with a "Safety" section, so why do you want it with unsafe blocks? FYI
|
There are some requirements for a call to an unsafe function to be safe. A comment with unsafe blocks can explain how the safety contract is respected. As shown in the example, it could be easier to maintain if the developer knows that unsafe block has been checked. This new lint can help developers to make sure that all usage of unsafe is documented. For checking comments, I don't know if there is a solution. The Rust repository does document their usage of unsafe so I thought "why not a lint?" |
An implementation for this seems to be in the works: #7557 |
Since #7748 was merged, I am closing this. |
What it does
Detects unsafe blocks used in safe functions missing a comment explaining/justifying the use of
unsafe
.Categories (optional)
clippy::pedantic
What is the advantage of the recommended code over the original code
unsafe
in the function is okayDrawbacks
None.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: