You’re misunderstanding me, I think.
My point is that X::precious in the example can be a Precious , and does not have to be a Option<Precious> . I would like to be able to statically express that X can not exist without a valid Precious .
This is what I was explaining how to do. You can use Option to make drop work, so you could get rid of Option and only add it back in before you actually do the drop. (Some variation of this.) I am skeptical it will be convenient, however.
I’m talking about the drop flag here, not the Precious. If you can always replace one Precious with another, then you don’t need the flag because you never change its value. This is basically an information theory problem.
No, in the proposed example I would not need such a flag because I ride on the already existing drop-functionality in the compiler. On drop, the compiler will simply pass the selected fields from that struct which is in the process of being dropped to a function of my choice. There’s no runtime flag needed, this will always happen during a drop of that type X .
The flag would still have to exist, it would just not be in your code, it would be automatically accounted for by the compiler’s drop machinery. This is what I meant when I said you wanted the flag moved.
In either case, to solve the problem of double-drop, you’d need to signal that your special functions don’t call drop, even though they take ownership. So you’re making a compile-time distinction, and I suggested that you might be able to achieve the same result with NoDrop, by telling the compiler to never automatically drop Precious, so that you can safely pass it into your own drop function, process it, and then unwrap it to tell the compiler to finish up.
EDIT: This is also starting to sound a bit like an X-Y problem; what are you actually trying to do with Precious that can’t be done in an &mut method using normal drop machinery?
EDIT 2: playing around with NoDrop, and I don’t see an easy way to get it to do this either…