mem_forget
checks if a type implements Drop
#9298
Labels
C-enhancement
Category: Enhancement of lints, like adding more cases or adding help messages
Description
mem_forget
currently only triggers if the type passed tomem::forget
implementsDrop
.However, if a type doesn't implement
Drop
, then that doesn't mean it lacks destructor code. For instance,String
andHashMap
currently don't implement it.Instead,
core::mem::needs_drop::<T>()
is usually used to check if dropping aT
invokes a destructor (the compiler-internal equivalent isrustc_middle::ty::Ty::needs_drop
). It is already being used for(drop|forget)_non_drop
andlet_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
The text was updated successfully, but these errors were encountered: