Open
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