rust-clippy
rust-clippy copied to clipboard
`mem_forget` checks if a type implements `Drop`
Description
mem_forget
currently only triggers if the type passed to mem::forget
implements Drop
.
However, if a type doesn't implement Drop
, then that doesn't mean it lacks destructor code. For instance, String
and HashMap
currently don't implement it.
Instead, core::mem::needs_drop::<T>()
is usually used to check if dropping a T
invokes a destructor (the compiler-internal equivalent is rustc_middle::ty::Ty::needs_drop
). It is already being used for (drop|forget)_non_drop
and let_underscore_drop
, but it is actually intended for optimization purposes only; it might spuriously return true. I don't know if it is the right thing to use here.
Version
No response
Additional Labels
@rustbot label: +C-enhancement