Skip to content

let_underscore_drop false positive for references to types that implement Drop #6633

Closed
@taylordotfish

Description

@taylordotfish

Lint name: let_underscore_drop

let_underscore_drop complains about let _ = ... bindings where the right-hand side is a reference to a type that implements Drop, even when the reference type itself does not implement Drop.

Example:

#![warn(clippy::pedantic)]

struct ImplementsDrop;

impl Drop for ImplementsDrop {
    fn drop(&mut self) {}
}

#[must_use]
fn push_new(vec: &mut Vec<ImplementsDrop>) -> &mut ImplementsDrop {
    vec.push(ImplementsDrop);
    vec.last_mut().unwrap()
}

fn main() {
    let mut vec = Vec::new();
    // Bind to underscore to silence `must_use` warning.
    let _ = push_new(&mut vec); // Clippy complains about this line!
}

let_underscore_drop complains about the let _ = ... line, but the right-hand side of the let binding has type &mut ImplementsDrop, which is a reference type that does not implement Drop, even though ImplementsDrop does.

Meta

  • cargo clippy -V: clippy 0.1.51 (4d0dd02 2021-01-23)
  • rustc -Vv:
rustc 1.51.0-nightly (4d0dd02ee 2021-01-23)
binary: rustc
commit-hash: 4d0dd02ee07bddad9136f95c9f7846ebf3eb3fc5
commit-date: 2021-01-23
host: powerpc64le-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions