rust-lang / rust-lang/rust-clippy
Lint request: drop_flags
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
Detects usage of drop flags.
Categories (optional)
- Kind: Restriction
Drop flags come with a hidden runtime cost, and can sometimes be an oversight.
Drawbacks
None.
Example
let x;
{
x = RequiresDrop;
x.do_something();
}
Could be written as:
{
let x = RequiresDrop;
x.do_something();
}
This is a restriction lint because there are some cases where drop flags seemingly make sense, such as a lazy or optional lock:
let _x; // _x is a LockGuard
if let Some(lock) = self.lock {
_x = lock.lock();
}
// protected code here
// drop flags take care of _x here
altho we'd argue this code is confusing and an explicit drop flag would be better:
let _x = self.lock.by_ref().map(Lock::lock); // _x is an Option<LockGuard> i.e. it has a drop flag attached to it in the form of an Option.
// protected code here
// Option takes care of _x, not drop flags
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
Start by locating existing Clippy restriction lints and the tests that exercise them, then investigate how Rust exposes variables requiring drop across branches. The work is done when the new lint detects the described drop-flag pattern, permits the documented optional-lock case, and has coverage for both examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100