Clarify drop_in_place safety by Manishearth · Pull Request #108684 · rust-lang/rust (original) (raw)

So about the

as far as the compiler is concerned still holds a bit-pattern which is valid for the type T

sentence: As far as I can tell, it doesn't make any new promises, so I wouldn't be super strongly opposed to including it. The reason I don't believe it makes any new promises is that 1) the sentence is already in the ManuallyDrop::drop documentation, and 2) I don't know what it's even supposed to mean.

That being said, I think we're better off not having it in at all. Quoting Manish from the UCG issue:

I wonder if we can make the sentence say something useful for the specific case (where you know the type's Drop impl) as opposed to the generic one.

That seems like a good idea. I'd suggest putting this sentence after the section on "Additionally, if T is not [Copy], using the pointed-to value after..." We can then make the whole paragraph say something like this (might need to work on the wording):

However, [drop_in_place()] does not modify the pointed-to value beyond any changes performed by [Drop::drop()]. This means that in cases where you know which type is being dropped and you know the behavior of the drop glue, calling drop_in_place multiple times on the same object may be fine.

It may be worth including an example