It is unspecified how many elements are removed from the vector if the Splice value is leaked.
So how is that test valid? Or is there a sort of hidden specification on how it “really works”, or perhaps the test is making sure the way it works doesn’t change?
Not every unit test of the standard library is written in the fashion of a spec-compliance test. They may be asserting the exact behavior of the current implementation, because that is, in most cases, easier to maintain than one which more precisely checks the documented guarantees and no more.
Thanks, I just wanted to be sure I wasn’t mis-understanding the situation, and especially that I hadn’t completely gone crazy and misunderstood what the documentation says! Perhaps a comment on the test to mention that is is not specification-based in this instance would be helpful. Or maybe it is obvious!
[ Incidentally, leaking the Splice seems to me to be a very strange and unlikely thing for anyone to do ]
Something it's important to remember is that leaking is a broad concept. Sometimes it's relevant only because of the safety implications re. lifetimes, but otherwise the question "what happens when X leaks" is equivalent to "what happens when X is accidentally held onto longer than expected".
I think in this case, if it leaks in the sense that it lives forever, then because the Vec is mutably borrowed by the Splice, the state of the Vec ( what elements have been removed from it ), is moot, because it cannot be observed… does that make sense?
Sure, but the goal isn't to be sound in the face of likely and non-strange code, the goal is to sound in the face of all safe code. And you can leak (not run the destructor of) Splice in safe code, so that possibility needs to be accounted for.