I've got an interesting and confusing error that can be seen in this playground example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f397a36f406ec6e1ddf6a8125286ec27. It seems to indicate that I can't implement
Drop for my type if that implementation requires a generic
T: Drop. I find this surprising since I apply conditions to generic parameters for trait implementations all the time.
I have three questions: Am I interpreting this error correctly? If so, why is this a restriction? Lastly, what is the recommended work-around, considering that I only need to implement
Drop for my type if
To give some extra context: I'm writing some bare-metal code, and I'm trying to create a wrapper type that will disable CPU interrupts and preemption while accessing the inner object. This is, in essence, a convenient way of creating critical sections of code. For what I'm doing, I believe it makes sense that "accessing the inner object" should include that object's destructor.
It is possible that I may be able to avoid disabling preemption during the destructor, I'm not actually sure at this point, but I'd rather be safe than sorry. I could also always implement
Drop regardless of whether or not
T does, but that just feels like a silly compromise since it relies on compiler optimizations to achieve the same generated code size and performance.