Alternative: why not have
trait Drop {
fn drop(&mut self);
fn drop_unwinding(&mut self) {
Drop::drop(self);
}
}
instead, with the semantics being that drop_unwinding is called when unwinding, and drop when not?
The case where you want to handle dropping during an unwind already need to implement both, so there’s no added “cost” there, unless you’re intending to see one of the following:
impl Drop for _ {
fn drop(&mut self) { unreachable!() }
// Or
fn drop(&mut self) {
Drop::drop_unwinding(self, probably_not);
}
fn drop_unwinding(&mut self, unwinding: bool) { ... }
}
Keep in mind also the language rules that make Drop::drop uncallable due to the special rule about moving out of &mut self in this case, so just delegating from one to the other is not trivial in std and would have to be special-cased (again) to be callable from the other drop function.
The advantage of redelegating to .drop(unwinding) being able to share the deconstruction code that’s the same between unwinding and not, I suppose.
I’m in favor of something like this, though!