New lint to minimize the unsafe block scope. #8022
Labels
A-lint
Area: New lints
S-needs-discussion
Status: Needs further discussion before merging or work can be started
What it does
Checks for
unsafe
blocks that contain safe code, which can be extracted to the outside safe code.Categories (optional)
Rust doesn't enforce memory safety guarantees in
unsafe
blocks. Having more code inside the unsafe block than necessary, might result in bugs which could be avoided by having the code in the save-code-scope. It also clearly indicates which part of an operation is unsafe.Drawbacks
Using the smallest unsafe code block possible might be less readable.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: