rust-lang / rust-lang/rust-clippy
New lint to minimize the unsafe block scope.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Checks for unsafe blocks that contain safe code, which can be extracted to the outside safe code.
Categories (optional)
- Kind: pedantic
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
unsafe {
let mut vec: Vec<u8> = Vec::with_capacity(128);
vec.set_len(100);
println!("{:#?}", vec);
}
Could be written as:
let mut vec: Vec<u8> = Vec::with_capacity(128);
unsafe {
vec.set_len(100);
}
println!("{:#?}", vec);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No implementation files, tests, or entry points are named. Start from the unsafe-block examples and define which safe statements may move outside the block, including the readability drawback. Done means the proposed lint consistently identifies unnecessary safe code inside unsafe blocks without flagging the intentionally grouped case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100