-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
A-lintArea: New lintsArea: New lintsE-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onL-restrictionLint: Belongs in the restriction lint groupLint: Belongs in the restriction lint group
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
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsE-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onL-restrictionLint: Belongs in the restriction lint groupLint: Belongs in the restriction lint group
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
kvverti commentedon Apr 3, 2021
Your first example does not require runtime conditional drop, since
r#use
takes ownership ofx
. The second is a valid demonstration of conditional drop.I would also suggest this be called
conditional_drop
, so as not to allude to any particular implementation.SoniEx2 commentedon May 8, 2021
maybe it should be called
hidden_runtime_cost
then, becauseOption<T>
also provides conditional drop. ;)