Skip to content

New lint: prevent dropping Results (and other must_use types) #6062

Open
@piegamesde

Description

@piegamesde

What it does

I just found the following code:

drop(env_logger::try_init());

Basically someone got a warning on an unused must_use type (in this case a Result), and thus "used" it … by dropping it. Tada, the warning's gone 🎉.

Categories (optional)

  • Kind: clippy::correctness

Drawbacks

None.

Example

drop(crate::try_do_stuff());

Could be written as:

crate::try_do_stuff().unwrap();

If the drop was intentional, it should be:

drop(crate::try_do_stuff().unwrap());

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-styleLint: Belongs in the style lint groupS-needs-discussionStatus: Needs further discussion before merging or work can be started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions