Is this splice test correct?
โ Rust ๐ 2026-02-25 ๐ค surdeus ๐๏ธ 1I just want to check my understanding here.
I am now starting to test my Vec implementation using the standard tests, one test is
#[test]
fn test_splice_forget() {
let mut v = vec![1, 2, 3, 4, 5];
let a = [10, 11, 12];
std::mem::forget(v.splice(2..4, a));
assert_eq!(v, &[1, 2]);
}
But the documentation says:
It is unspecified how many elements are removed from the vector if the
Splicevalue 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?
3 posts - 2 participants
๐ท๏ธ Rust_feed