Closed
Description
The false positive detection done in rust-lang/rust-clippy#9491 is actually too restrictive. The test is whether drop is used with the following pattern: pat => drop(fun(args, ...))
. In particular, this doesn't match pat => drop(expr)
which would be more general and cover things like pat => drop(fun(args, ...)?)
(notice the ?
).
Here's an example where the false positive triggers:
fn foo() -> Result<u8, ()> {
println!("doing foo");
Ok(0) // result is not always useful, the side-effect matters
}
fn bar() {
println!("doing bar");
}
pub fn stuff() -> Result<(), ()> {
match 42 {
0 => drop(foo()?), // drop is needed because we only care about side-effects
1 => bar(),
_ => (), // doing nothing (no side-effects needed here)
}
Ok(())
}
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> src/lib.rs:11:14
|
11 | 0 => drop(foo()?), // drop is needed because we only care about side-effects
| ^^^^^------^
| |
| argument has type `u8`
|
= note: use `let _ = ...` to ignore the expression or result
= note: `#[warn(dropping_copy_types)]` on by default