Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
taylordotfish opened this issue Jan 24, 2021 · 0 comments · Fixed by #6682
Closed
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-positive Issue: The lint was triggered on code it shouldn't have T-middle Type: Probably requires verifiying types

Comments

@taylordotfish
Copy link

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
@taylordotfish taylordotfish added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jan 24, 2021
@camsteffen camsteffen added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types labels Jan 26, 2021
@bors bors closed this as completed in d792210 Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-positive Issue: The lint was triggered on code it shouldn't have T-middle Type: Probably requires verifiying types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants