forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#125552 - matthiaskrgr:rollup-f1yybpn, r=matth…
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#121377 (Stabilize `LazyCell` and `LazyLock`) - rust-lang#122986 (Fix c_char on AIX) - rust-lang#123803 (Fix `VecDeque::shrink_to` UB when `handle_alloc_error` unwinds.) - rust-lang#124080 (Some unstable changes to where opaque types get defined) - rust-lang#124667 (Stabilize `div_duration`) - rust-lang#125472 (tidy: validate LLVM component names in tests) - rust-lang#125523 (Exit the process a short time after entering our ctrl-c handler) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
76 changed files
with
590 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#![feature(alloc_error_hook, allocator_api)] | ||
|
||
use std::{ | ||
alloc::{set_alloc_error_hook, AllocError, Allocator, Layout, System}, | ||
collections::VecDeque, | ||
panic::{catch_unwind, AssertUnwindSafe}, | ||
ptr::NonNull, | ||
}; | ||
|
||
#[test] | ||
fn test_shrink_to_unwind() { | ||
// This tests that `shrink_to` leaves the deque in a consistent state when | ||
// the call to `RawVec::shrink_to_fit` unwinds. The code is adapted from #123369 | ||
// but changed to hopefully not have any UB even if the test fails. | ||
|
||
struct BadAlloc; | ||
|
||
unsafe impl Allocator for BadAlloc { | ||
fn allocate(&self, l: Layout) -> Result<NonNull<[u8]>, AllocError> { | ||
// We allocate zeroed here so that the whole buffer of the deque | ||
// is always initialized. That way, even if the deque is left in | ||
// an inconsistent state, no uninitialized memory should be accessed. | ||
System.allocate_zeroed(l) | ||
} | ||
|
||
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | ||
unsafe { System.deallocate(ptr, layout) } | ||
} | ||
|
||
unsafe fn shrink( | ||
&self, | ||
_ptr: NonNull<u8>, | ||
_old_layout: Layout, | ||
_new_layout: Layout, | ||
) -> Result<NonNull<[u8]>, AllocError> { | ||
Err(AllocError) | ||
} | ||
} | ||
|
||
set_alloc_error_hook(|_| panic!("alloc error")); | ||
|
||
let mut v = VecDeque::with_capacity_in(15, BadAlloc); | ||
v.push_back(1); | ||
v.push_front(2); | ||
// This should unwind because it calls `BadAlloc::shrink` and then `handle_alloc_error` which unwinds. | ||
assert!(catch_unwind(AssertUnwindSafe(|| v.shrink_to_fit())).is_err()); | ||
// This should only pass if the deque is left in a consistent state. | ||
assert_eq!(v, [2, 1]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.