diff options
| author | bors <bors@rust-lang.org> | 2019-05-26 06:09:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-05-26 06:09:08 +0000 |
| commit | 2268d9923bcb34a6c921d285cca7fa3dba857c02 (patch) | |
| tree | 51812c38d2a32da67a7c68f0e5301c500cf2e3ad /src/liballoc/tests | |
| parent | 572892c324cde896df0c4a1e9ed4896b1832a4fd (diff) | |
| parent | 8d247e716bc1ed4039f9c696ccf0eb975975f295 (diff) | |
| download | rust-2268d9923bcb34a6c921d285cca7fa3dba857c02.tar.gz rust-2268d9923bcb34a6c921d285cca7fa3dba857c02.zip | |
Auto merge of #61201 - Centril:rollup-975knrk, r=Centril
Rollup of 9 pull requests Successful merges: - #61087 (Tweak `self` arg not as first argument of a method diagnostic) - #61114 (Vec: avoid creating slices to the elements) - #61144 (Suggest borrowing for loop head on move error) - #61149 (Fix spelling in release notes) - #61161 (MaybeUninit doctest: remove unnecessary type ascription) - #61173 (Auto-derive Encode and Decode implementations of DefPathTable) - #61184 (Add additional trace statements to the const propagator) - #61189 (Turn turbo 🐟 🍨 into an error) - #61193 (Add comment to explain why we change the layout for Projection) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc/tests')
| -rw-r--r-- | src/liballoc/tests/vec.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 3307bdf94f9..5ddac673c9f 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -1152,3 +1152,24 @@ fn test_try_reserve_exact() { } } + +#[test] +fn test_stable_push_pop() { + // Test that, if we reserved enough space, adding and removing elements does not + // invalidate references into the vector (such as `v0`). This test also + // runs in Miri, which would detect such problems. + let mut v = Vec::with_capacity(10); + v.push(13); + + // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay. + let v0 = unsafe { &*(&v[0] as *const _) }; + + // Now do a bunch of things and occasionally use `v0` again to assert it is still valid. + v.push(1); + v.push(2); + v.insert(1, 1); + assert_eq!(*v0, 13); + v.remove(1); + v.pop().unwrap(); + assert_eq!(*v0, 13); +} |
