For the purpose of this post, a droppable type can be assigned to _ or go out of scope without causing a compiler error.
Since Copy already requires the absence of a destructor and TrivialDrop is proposed as an auto-implemented trait, this shouldn’t be a breaking change. It just splits out part of the requirements of Copy into a separate trait.
I would never have expected the difference between user implemented Drop and a compiler implemented one that calls the user-implement Drop of the type’s fields to affect which traits a type implements.
For a fun exercise, try to predict which standard collections fulfill the Drop bound, and which do not.
I think refactoring a type to move its resource ownershop into an inner holder type should not be a breaking change. So
struct Collection{
}
impl Drop for Collection
{
fn drop(&mut self)
{
}
}
could be turned into:
impl Drop for Inner
{
fn drop(&mut self)
{
}
}
struct Collection{
inner:Inner
}
without breaking consumers.
Disallowing Drop as trait bound introduces breakage, but only in cases that no sane code will hit.
Introducing TrivialDrop should not result in any breakage.
Introducing TrivialDrop shouldn’t be too complex, since deriving Copy already requires the same logic. And it might even reduce the complexity of NLL slightly, since it could take advantage of already implemented traits, instead of duplicating the logic.