Clippy lints / Suspicious
Clippy lint · Suspicious · checked with Clippy 0.1.99
clippy::drop_non_drop: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
What it meansChecks for calls to std::mem::drop with a value that does not implement Drop. It is in the suspicious group and warns by default.
What you see
warning: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> main.rs:5:1 | 5 | std::mem::drop(x); | ^^^^^^^^^^^^^^^^^ | note: argument has type `main::Foo` --> main.rs:5:16 | 5 | std::mem::drop(x); | ^ = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#drop_non_drop = note: `#[warn(clippy::drop_non_drop)]` on by default
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
Calling std::mem::drop is no different than dropping such a type. A different value may have been intended.
Code that is most likely wrong or useless. Warns by default.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
struct Foo;
let x = Foo;
std::mem::drop(x);
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::drop_non_drop)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
drop_non_drop = "allow"One run
cargo clippy -- -A clippy::drop-non-dropThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for calls to std::mem::drop with a value that does not implement Drop.
Why is this bad?
Calling std::mem::drop is no different than dropping such a type. A different value may
have been intended.
Example
struct Foo;
let x = Foo;
std::mem::drop(x);
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- deprecated_clippy_cfg_attr`feature = "cargo-clippy"` was replaced by `clippy`
- doc_nested_refdefslink reference defined in list item
- doc_suspicious_footnoteslooks like a footnote ref, but has no matching footnote
- duplicate_modfile is loaded as a module multiple times: `main.rs`
- duplicated_attributesduplicated attribute
- empty_docsempty doc comment
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::deprecated_clippy_cfg_attr`feature = "cargo-clippy"` was replaced by `clippy`Read it next →Did this answer your question?