rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

The lint docs misrepresent trait `Drop`

Open kadiwa4 opened this issue 2 years ago • 0 comments

The reason why Drop is a trait is because adding a drop method to a type is similar to implementing a trait on it. Other than that, Drop does not really behave like a trait. 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 used to check if dropping a T invokes a destructor.

drop_non_drop and forget_non_drop should not mention the trait Drop in their name or documentation, it is misleading.

The descriptions for let_underscore_drop and forget_copy also don’t explain Drop correctly.

kadiwa4 avatar Jul 22 '22 09:07 kadiwa4