Skip to content

Lint request: drop_flags #7025

Open
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-hardCall for participation: This a hard problem and requires more experience or effort to work onL-restrictionLint: Belongs in the restriction lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions