rust/library/alloc/tests
Matthias Krüger 7fb81229d3
Rollup merge of #123803 - Sp00ph:shrink_to_fix, r=Mark-Simulacrum
Fix `VecDeque::shrink_to` UB when `handle_alloc_error` unwinds.

Fixes #123369

For `VecDeque` it's relatively simple to restore the buffer into a consistent state so this PR does just that.

Note that with its current implementation, `shrink_to` may change the internal arrangement of elements in the buffer, so e.g. `[D, <uninit>, A, B, C]` will become `[<uninit>, A, B, C, D]` and `[<uninit>, <uninit>, A, B, C]` may become `[B, C, <uninit>, <uninit>, A]` if `shrink_to` unwinds. This shouldn't be an issue though as we don't make any guarantees about the stability of the internal buffer arrangement (and this case is impossible to hit on stable anyways).

This PR also includes a test with code adapted from #123369 which fails without the new `shrink_to` code. Does this suffice or do we maybe need more exhaustive tests like in #108475?

cc `@Amanieu`

`@rustbot` label +T-libs
2024-05-25 22:15:17 +02:00
..
arc.rs remove redundant imports 2023-12-10 10:56:22 +08:00
autotraits.rs apply fmt 2024-01-11 15:04:48 +03:00
borrow.rs remove redundant imports 2023-12-10 10:56:22 +08:00
boxed.rs rm const traits in libcore 2023-04-16 06:49:27 +00:00
btree_set_hash.rs Include the length in BTree hashes 2021-10-01 12:29:09 -07:00
c_str.rs Remove use of reverted std::ffi::c_char 2022-04-27 14:01:04 -07:00
const_fns.rs fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
cow_str.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
fmt.rs rename ptr::invalid -> ptr::without_provenance 2024-02-21 20:15:52 +01:00
heap.rs Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
lib.rs Step bootstrap cfgs 2024-05-01 22:19:11 -04:00
linked_list.rs Classify BinaryHeap & LinkedList unit tests as such 2022-03-11 11:33:59 +01:00
rc.rs remove redundant imports 2023-12-10 10:56:22 +08:00
slice.rs Stabilize slice_group_by 2023-11-07 17:46:00 +01:00
str.rs fix #124714 str.to_lowercase sigma handling 2024-05-08 17:05:10 +02:00
string.rs try_with_capacity for Vec, VecDeque, String 2024-03-01 18:24:02 +00:00
task.rs will_wake tests fail on Miri and that is expected 2024-03-05 09:33:55 +01:00
thin_box.rs Make use of pointer::is_aligned[_to] 2022-08-21 15:46:03 +04:00
vec_deque_alloc_error.rs Move test_shrink_to_unwind to its own file. 2024-05-07 19:43:54 +00:00
vec_deque.rs try_with_capacity for Vec, VecDeque, String 2024-03-01 18:24:02 +00:00
vec.rs Implement Vec::pop_if 2024-03-26 18:25:24 -04:00